MISRA C++:2008 Rule 5-3-3
The unary & operator shall not be overloaded
Description
Rule Definition
The unary & operator shall not be overloaded.
Rationale
Overloading the address-of (the unary &
) operator in a class can
lead to undefined behavior if you use C++ version C++11 or older. Overloading the unary
&
operator is unspecified behavior if you use C++ version C++14 or
newer. The undefined or unspecified behavior occurs if both of these conditions are true:
You take the address of an incomplete type.
The type contains an overloaded unary
&
operator.
Overloading the &
operator makes the code harder to
understand because *&a
might not evaluate to
a
.
Polyspace Implementation
Polyspace® reports a defect if you overload the unary &
operator.
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: Expressions |
Category: Required |
Version History
Introduced in R2013b