Reference type declared with a redundant const or
volatile qualifier
This defect
occurs when a variable with reference type is declared with the const or
volatile qualifier, for
instance:
char &const c;
The C++14 Standard states that const or volatile
qualified references are ill formed (unless they are introduced through a
typedef, in which case they are ignored). For instance, a reference to
one variable cannot be made to refer to another variable. Therefore, using the
const qualifier is not required for a variable with a reference
type.
Often the use of these qualifiers indicate a coding error. For instance, you meant to
declare a reference to a const-qualified
type:
char const &c;
const-qualified
reference:char &const c;
c to be immutable but see a different value of c
compared to its value at declaration.See if the const or volatile qualifier is
incorrectly placed. For instance, see if you wanted to refer to a
const-qualified type and
entered:
char &const c;
char const &c;
const or
volatilequalifier before the & operator.
Otherwise, remove the redundant qualifier.| Group: Good practice |
| Language: C++ |
| Default: Off |
Command-Line Syntax:
CV_QUALIFIED_REFERENCE_TYPE |
| Impact: Low |
C++ reference to
const-qualified type with subsequent modification | Find defects (-checkers) | Qualifier removed in conversion | Unreliable cast of function pointer | Unreliable cast of pointer | Writing to const qualified object