MISRA C++:2023 Rule 16.5.2
Description
Rule Definition
The address-of operator shall not be overloaded. 1
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
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.