35 lines
889 B
Plaintext
35 lines
889 B
Plaintext
The {cpp} specification forbids the qualification of reference types with ``++const++`` or ``++volatile++`` unless it happens via a ``++typedef++``, in which case it's ignored. Most compilers treat such direct qualifications as errors, but the Microsoft compiler allows them.
|
|
|
|
|
|
This rule raises an issue on both types of ``++const++`` qualification.
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
----
|
|
void example(char c) {
|
|
char & const direct = c; // Noncompliant
|
|
|
|
typedef char & T;
|
|
const T indirect = c; // Noncompliant
|
|
}
|
|
----
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
----
|
|
void example(char c) {
|
|
char & direct = c; // or: const char & direct = c;
|
|
|
|
typedef char & T;
|
|
T indirect = c;
|
|
}
|
|
----
|
|
|
|
|
|
== See
|
|
|
|
* https://www.securecoding.cert.org/confluence/display/cplusplus/DCL52-CPP.+Never+qualify+a+reference+type+with+const+or+volatile[CERT, DCL52-CPP.] - Never qualify a reference type with const or volatile
|
|
|