MISRA C++:2008 Rule 5-2-11
The comma operator, && operator and the || operator shall not be overloaded
Description
Rule Definition
The comma operator, && operator and the || operator shall not be overloaded.
Rationale
When you overload an operator, the overloaded operator behaves as a function call. The
comma operator, the &&
operator, and the ||
operator have certain behaviors that cannot be replicated by their overloaded counterpart.
For instance, a compiler might short circuit the builtin &&
or
||
operators. But such short circuiting is not possible when you use an
overloaded version of these operators.
Overloading these operators creates confusion about how these operators behave. Avoid
overloading the comma operator, the &&
operator, and the
||
operator.
Polyspace Implementation
Polyspace® flags the overloading of these operators:
Comma operator
&&
operator||
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