rspec/rules/S5822/cfamily/rule.adoc

40 lines
953 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
{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.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
void test1(int p) {
switch (p) {
case 0:
case 1:;
[[std::fallthrough]]; // Noncompliant [[std::fallthrough]] isn't a defined attribute
default:
break;
}
}
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
void test1(int p) {
switch (p) {
case 0:
case 1:;
[[fallthrough]];
default:
break;
}
}
----