AutosarC++17_03-M5.3.3¶
The unary & operator shall not be overloaded
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
[Undefined 5.3.1(4)]
Rationale
Taking the address of an object of incomplete type where the complete type contains a user declared operator & leads to undefined behaviour.
Example
// A.h
class A
{
public:
A * operator & ( ); // Non-compliant
}; // f1.cc
class A;
void f ( A & a )
{
&a; // uses built-in operator &
}
// f2.cc
#include "A.h"
void f2 ( A & a )
{
&a; // use user-defined operator &
}
See also
ISO/IEC 14882:2003 §5.3.1(4)
Note
For legal reasons, this rule’s description is not part of the public documentation.