Rule M7-1-2 (required, implementation, automated)

A pointer or reference parameter in a function shall be declared as pointer to const or reference to const if the corresponding object is not modified. See MISRA C++ 2008 [7]


## See also

C++ Core Guidelines [11]: Con.3: By default, pass pointers and references to
consts.
Rule A7-1-3 (required, implementation, automated) CV-qualifiers shall
be placed on the right hand side of the type that is a typedef or a
using name.
## 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

```cpp
// $Id: A7-1-3.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
#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*

ConstIntPtr const ptr6 =

// std::int32_t*

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

const, not const const

}

See also

HIC++ v4.0 [9]: 7.1.4 Place CV-qualifiers on the right hand side of the type they apply to