Only nullptr literal shall be used as the null-pointer-constraint
Only nullptr literal shall be used as the null-pointer-constraint.
nullptr was introduced in C++11 to support the concept of a pointer
that does not point to a valid object. Before C++11, the macro NULL and
the constant 0 were the only ways to define the null pointer constant. Using
nullptr to indicate null-pointers has several advantages over using
NULL or 0. For instance:
nullptr can be used with any type of null-pointer without
requiring an implicit cast.
nullptr literals allow parameter forwarding by using a template
function.
NULL is a macro that expands to an integer
0 which is cast into void* type. Using
NULL or 0 to indicate null-pointers is contrary to
developer expectation. If code expecting nullptr encounters
NULL or 0 instead, it might lead to confusion or
unexpected behavior.
Polyspace® flags the use of NULL or 0 instead of
nullptr to indicate a null-pointer. This rule does not check for
conversion between NULL and 0. See AUTOSAR C++14 Rule M4-10-1.
If you expect a rule violation but do not see it, refer to Coding Standard Violations Not Displayed.
| Group: Standard conversions |
| Category: Required, Automated |
AUTOSAR C++14 Rule
M4-10-1 | AUTOSAR C++14
Rule M4-10-2 | Check AUTOSAR C++
14 (-autosar-cpp14)