Qt-Autosar-A4.10.1¶
Only nullptr literal shall be used as the null-pointer-constant
Required inputs: IR
| Level | required |
|---|---|
| Target | architecture / design / implementation |
| Enforcement | automated |
Rationale
In C++, the literal NULL is both the null-pointer-constant and an integer type. To meet developer expectations, only nullptr pointer literal shall be used as the null-pointer- constant.
Note that, nullptr pointer literal allows parameters forwarding via a template function.
Example
//% $Id: A4-10-1.cpp 298086 2017-11-24 11:13:27Z michal.szczepankiewicz $
#include <cstddef>
#include <cstdint>
void F1(std::int32_t);
void F2(std::int32_t*);
void F3()
{
F1(0); // Compliant
F1(NULL); // Non-compliant - NULL used as an integer,
// compilable
// f1(nullptr); // Non-compliant - nullptr used as an integer
// compilation error
F2(0); // Non-compliant - 0 used as the null pointer constant
F2(NULL); // Non-compliant - NULL used as the null pointer constant
F2(nullptr); // Compliant
}
void F4(std::int32_t*);
template <class F, class A>
void F5(F f, A a)
{
F4(a);
}
void F6()
{
// f5(f4, NULL); // Non-compliant - function f4(std::int32_t) not declared
F5(F4, nullptr); // Compliant
}
See Also
- HIC++ v4.0 [9]: 2.5.3 Use nullptr for the null pointer constant
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
null_constant |
Only nullptr literal shall be used as the null-pointer-constant. |
None |
False |
zero_as_null |
Use of literal zero (0) as null-pointer-constant, use {} instead |
None |
False |
Options¶
This rule shares the following common options: confidence, exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
require_nullptr¶
require_nullptr : bool = True