rspec/rules/S977/cfamily/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

77 lines
1.4 KiB
Plaintext

== Why is this an issue?
Preprocessing directives (lines that start with ``++#++``) can be used to conditionally include or exclude code from compilation. Malformed preprocessing directives could lead to the exclusion or inclusion of more code than was intended. Therefore all preprocessing directives should be syntactically meaningful.
=== Noncompliant code example
[source,cpp]
----
#define AAA 2
...
int foo(void)
{
int x = 0;
...
#ifndef AAA
x = 1;
#else1 /* Noncompliant */
x = AAA;
#endif
...
return x;
}
----
=== Compliant solution
[source,cpp]
----
#define AAA 2
...
int foo(void)
{
int x = 0;
...
#ifndef AAA
x = 1;
#else
x = AAA;
#endif
...
return x;
}
----
== Resources
* MISRA C:2004, 19.16 - Preprocessing directives shall be syntactically meaningful even when excluded by preprocessor.
* MISRA {cpp}:2008, 16-0-8 - If the # token appears as the first token on a line, then it shall be immediately followed by a preprocessing token.
* MISRA C:2012, 20.13 - A line whose first token is # shall be a valid preprocessing directive
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
"xxx" is not a valid directive, correct it or delete its contents.
'''
== Comments And Links
(visible only on this page)
=== is duplicated by: S965
endif::env-github,rspecator-view[]