rspec/rules/S5822/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

59 lines
1.3 KiB
Plaintext

== Why is this an issue?
{cpp}11 introduced "Attributes". They provide a unified syntax to specify additional information about your code.
They can be applied to various things like types, variables, functions, names, blocks, and translation units.
{cpp} defines some standard attributes like \[[noreturn]], \[[nodiscard]], \[[deprecated]], \[[fallthrough]]...
Unfortunately, it is possible to use unknown attributes: attributes that are not defined. Your code will compile, but the unknown attribute will be silently ignored. This means that your code will not behave in the way you expected.
=== Noncompliant code example
[source,cpp]
----
void test1(int p) {
switch (p) {
case 0:
case 1:;
[[std::fallthrough]]; // Noncompliant [[std::fallthrough]] isn't a defined attribute
default:
break;
}
}
----
=== Compliant solution
[source,cpp]
----
void test1(int p) {
switch (p) {
case 0:
case 1:;
[[fallthrough]];
default:
break;
}
}
----
ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)
=== on 7 May 2020, 09:12:42 Geoffray Adde wrote:
Whatre you intending to do for compiler-specific attributes? have a whitelist of namespaces?
for example:
https://docs.microsoft.com/en-us/cpp/cpp/attributes?view=vs-2019
endif::env-github,rspecator-view[]