The C++ 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;
}