53 lines
1.5 KiB
Plaintext
53 lines
1.5 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Trigraphs are denoted by a sequence of 2 question marks followed by a specified third character (e.g. ??- represents a '~' (tilde) character and ??) represents a ']'). They can cause accidental confusion with other uses of two question marks.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,cpp]
|
|
----
|
|
static const char str[] = "(Date should be in the form ??-??-??)"; // Noncompliant. Evaluates to "(Date should be in the form ~~]"
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,cpp]
|
|
----
|
|
static const char str[] = "(Date should be in the form ?" "?-?" "?-?" ?)"; // adjacent string literals concatenated at compile time
|
|
static const char str2[] = "(Date should be in the form ?-?-?)"; // problem avoided by eliminating 2nd '?' in each sequence
|
|
static const char str3[] = "(Date should be in the form ? ?-? ?-? ?)"; // problem avoided by spacing '?'s out
|
|
----
|
|
|
|
|
|
== Resources
|
|
|
|
=== Documentation
|
|
|
|
* {cpp} reference - https://en.cppreference.com/w/cpp/language/operator_alternative[Alternative operator representations: Trigraphs]
|
|
|
|
=== Standards
|
|
|
|
* CERT - https://wiki.sei.cmu.edu/confluence/x/uNUxBQ[PRE07-C. - Avoid using repeated question marks]
|
|
|
|
=== External coding guidelines
|
|
|
|
* MISRA C:2004, 4.2 - Trigraphs shall not be used
|
|
* MISRA {cpp}:2008, 2-3-1 - Trigraphs shall not be used
|
|
* MISRA C:2012, 4.2 - Trigraphs shall not be used
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Remove all trigraph sequences: ??=, ??/, ??', ??(, ??), ??!, ??<, ??>, ??-.
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|