AUTOSAR C++14 Rule A4-10-1
Description
Rule Definition
Only nullptr literal shall be used as the null-pointer-constraint.
Rationale
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 Implementation
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
.
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, Automated |
Version History
Introduced in R2020a