MISRA C++:2023 Rule 7.11.1
Description
Rule Definition
nullptr
shall be the only form of the
null-pointer-constant
Rationale
With nullptr
, function overloading works more predictably. When using
0
or NULL
, the value can be interpreted as an
integer, leading to unexpected behavior if multiple overloads are available.
nullptr
unambiguously identifies a null pointer, ensuring the correct
function overload is chosen when a null pointer is intended as an argument.
Using a named constant or macro to represent a null value in your code does not change the resulting compiled code. The pointer is still assigned a null value, and the distinction between the two approaches is abstracted away during compilation.
Polyspace Implementation
The rule checker reports a violation when the code uses any other integral literal,
including NULL
, to represent the null-pointer constant instead of using
nullptr
.
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: Standard Conversions |
Category: Required |
Version History
Introduced in R2024b