AutosarC++17_03-A7.1.3

CV-qualifiers shall be placed on the right hand side of the type that is a typedef or a using name

Required inputs: IR

Rationale

If the type is a typedef or a using name, placing const or volatile qualifier on the left hand side may result in confusion over what part of the type the qualification applies to.

Example
// $Id: A7-1-3.cpp 271687 2017-03-23 08:57:35Z piotr.tanski $
#include <cstdint>
using IntPtr = std::int32_t *;
using IntConstPtr = std::int32_t *const;
using ConstIntPtr = const std::int32_t *;
void fn(const std::uint8_t &input) // Compliant
{
std::int32_t value1 = 10;
std::int32_t value2 = 20;

const IntPtr ptr1 = &value1; // Non-compliant - deduced type is std::int32_t*
                       // const, not const std::int32_t*

// ptr1 = &value2;     // Compilation error, ptr1 is read-only variable

IntPtr const ptr2 =
&value1; // Compliant - deduced type is std::int32_t* const

// ptr2 = &value2;     // Compilation error, ptr2 is read-only variable

IntConstPtr ptr3 = &value1; // Compliant - type is std::int32_t* const, no
                      // additional qualifiers needed

// ptr3 = &value2;     // Compilation error, ptr3 is read-only variable

ConstIntPtr ptr4 = &value1; // Compliant - type is const std::int32_t*

const ConstIntPtr ptr5 = &value1; // Non-compliant, type is const
                            // std::int32_t* const, not const const
                            // std::int32_t*
ConstIntPtr const ptr6 =
&value1; // Compliant - type is const std::int32_t* const
}
See Also
  • HIC++ v4.0 [8]: 7.1.4 Place CV-qualifiers on the right hand side of the type they apply to

Possible Messages

Key

Text

Severity

Disabled

lhs_cv_qualifier

CV qualifier on the lhs of a type.

None

False

Options

allow_nonpointer_typedefs

allow_nonpointer_typedefs : bool = False

Whether to allow the qualifier on the rhs of a type, if it is a non-pointer typedef.
 

allowed_typedefs

allowed_typedefs

Type: set[bauhaus.analysis.config.ShortTypeName | bauhaus.analysis.config.QualifiedName]

Default: {'clock_t', 'div_t', 'fpos_t', 'int16_t', 'int32_t', 'int64_t', 'int8_t', 'int_fast16_t', 'int_fast32_t', 'int_fast64_t', 'int_fast8_t', 'int_least16_t', 'int_least32_t', 'int_least64_t', 'int_least8_t', 'intmax_t', 'intptr_t', 'ldiv_t', 'lldiv_t', 'max_align_t', 'nullptr_t', 'ptrdiff_t', 'size_t', 'time_t', 'uint16_t', 'uint32_t', 'uint64_t', 'uint8_t', 'uint_fast16_t', 'uint_fast32_t', 'uint_fast64_t', 'uint_fast8_t', 'uint_least16_t', 'uint_least32_t', 'uint_least64_t', 'uint_least8_t', 'uintmax_t', 'uintptr_t'}

Set of names for typedefs/usings that are allowed (e.g. int32_t).