AUTOSAR C++14 Rule A7-1-3
CV-qualifiers shall be placed on the right hand side of the type that is a typedef or a using name
Description
Rule Definition
CV-qualifiers shall be placed on the right hand side of the type that is a typedef or a using name.
Rationale
Suppose a typedef or using statement defines a
pointer type. For instance:
using IntPtr = std::int32_t*;
const-qualification of the type written
as:const IntPtr ptr = &someValue;
const (std::int32_t*) ptr = &someValue;
ptr is a constant pointer, which cannot be reassigned to
another memory location. However, a developer or reviewer might expect this
expansion:(const std::intr32_t) *ptr = &someValue;
ptr is a pointer to a constant, which means that the
contents of the location that ptr points to, or *ptr,
cannot be changed.To avoid this confusion, place a const or volatile
qualifier to the right of a data type defined through typedef or
using. For
instance:
IntPtr const ptr = &someValue;
std::intr32_t const *ptr = &someValue;
ptr a constant pointer.Polyspace Implementation
The checker reports a violation if const or
volatile qualifiers are placed on the left side of data types defined
through typedef or using statements.
The checker reports violations on both pointer and nonpointer data types. The checker
does not report a violation on typedefs defined in the
std namespace.
Troubleshooting
If you expect a rule violation but Polyspace® does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
| Group: Declaration |
| Category: Required, Automated |