MISRA C++:2023 Rule 16.5.2
Description
Rule Definition
The address-of 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 violation 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: Overloading |
Category: Required |
Version History
Introduced in R2024b