rspec/rules/S797/cfamily/rule.adoc

40 lines
1.3 KiB
Plaintext
Raw Normal View History

== 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
2022-02-04 17:28:24 +01:00
[source,cpp]
----
static const char str[] = "(Date should be in the form ??-??-??)"; // Noncompliant. Evaluates to "(Date should be in the form ~~]"
----
=== Compliant solution
2022-02-04 17:28:24 +01:00
[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
* 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
* https://wiki.sei.cmu.edu/confluence/x/uNUxBQ[CERT, PRE07-C.] - Avoid using repeated question marks
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
endif::env-github,rspecator-view[]