PTR-overload (C++ only)
In this section:
Synopsis
An & operator is overloaded.
Enabled by default
No
Severity/Certainty
Low/Low

Full description
The address of an object of incomplete type is taken. Because the complete type contains a user-declared & operator, this leads to undefined behavior. This check is identical to MISRAC++2008-5-3-3, MISRAC++2023-16.5.2.
Coding standards
- MISRA C++ 2008 5-3-3
(Required) The unary & operator shall not be overloaded.
- MISRA C++ 2023 16.5.2
(Required) The address-of operator shall not be overloaded
Code examples
The following code example fails the check and will give a warning:
class C{
bool x;
bool* operator&();
};
bool* C::operator&(){
return &x;
}
The following code example passes the check and will not give a warning about this issue:
class C{
int x;
int operator+(int other);
};
int C::operator+(int other){
return x + other;
}