2023-05-03 11:06:20 +02:00
== Why is this an issue?
2021-04-28 18:08:03 +02:00
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.
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2021-04-28 18:08:03 +02:00
2022-02-04 17:28:24 +01:00
[source,cpp]
2021-04-28 18:08:03 +02:00
----
static const char str[] = "(Date should be in the form ??-??-??)"; // Noncompliant. Evaluates to "(Date should be in the form ~~]"
----
2023-05-03 11:06:20 +02:00
=== Compliant solution
2021-04-28 18:08:03 +02:00
2022-02-04 17:28:24 +01:00
[source,cpp]
2021-04-28 18:08:03 +02:00
----
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
----
2023-05-03 11:06:20 +02:00
== Resources
2021-04-28 18:08:03 +02:00
2023-09-25 13:40:43 +02:00
=== 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
2021-04-28 18:08:03 +02:00
* 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
2023-09-25 13:40:43 +02:00
2021-04-28 18:08:03 +02:00
2021-09-20 15:38:42 +02:00
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== Message
Remove all trigraph sequences: ??=, ??/, ??', ??(, ??), ??!, ??<, ??>, ??-.
2021-09-20 15:38:42 +02:00
endif::env-github,rspecator-view[]