GeneralPurpose-UseOfZeroAsNull

The macro NULL and C++11 nullptr shall be the only permitted forms of null pointer constant

Required inputs: IR

Using literal zero (0) as a null pointer constant is ambiguous: it could be read as the integer zero or as a pointer. The macro NULL or C++11 nullptr makes the intent explicit and prevents confusion. Code using proper null pointer constants is clearer and less error-prone.
Bad code (literal zero as null):
int* ptr = 0;          // ERROR: ambiguous - is this int zero or null pointer?
if (ptr == 0) { }      // Unclear intent
Good code (using NULL macro):
int* ptr = NULL;       // OK: explicit null pointer constant
if (ptr == NULL) { }   // Clear intent
Good code (using C++11 nullptr):
int* ptr = nullptr;    // OK: type-safe null pointer
if (ptr == nullptr) {} // Clear and type-safe

Possible Messages

Key

Text

Severity

Disabled

zero_as_null

Use of literal zero (0) as null-pointer-constant, use {} instead

None

False

Options

require_nullptr

require_nullptr : bool = False

Require C++11 nullptr instead of macro NULL or literal zero (0).