modernize-use-nullptr#
The check converts the usage of null pointer constants (e.g. NULL, 0)
to use the new C++11 and C23 nullptr keyword.
It also replaces references to decltype(nullptr) with std::nullptr_t
from <cstdef>.
Example#
void assignment() {
char *a = NULL;
char *b = 0;
char c = 0;
}
int *ret_ptr() {
return 0;
}
void expect_null(decltype(nullptr));
transforms to:
#include <cstddef>
void assignment() {
char *a = nullptr;
char *b = nullptr;
char c = 0;
}
int *ret_ptr() {
return nullptr;
}
void expect_null(std::nullptr_t);
Options#
- IgnoredTypes#
Semicolon-separated list of regular expressions to match pointer types for which implicit casts will be ignored. Default value: std::_CmpUnspecifiedParam::;^std::__cmp_cat::__unspec.
- NullMacros#
Comma-separated list of macro names that will be transformed along with
NULL. By default this check will only replace theNULLmacro and will skip any similar user-defined macros.
- UseNullptrT#
Boolean controlling whether we should replace
decltype(nullptr)with the typestd::nullptr_tfrom<cstddef>. Defaults totrue.
- IncludeStyle#
A string specifying which include-style is used, llvm or google. Default is llvm.
Example#
#define MY_NULL (void*)0
void assignment() {
void *p = MY_NULL;
}
transforms to:
#define MY_NULL NULL
void assignment() {
int *p = nullptr;
}
if the NullMacros option is set to MY_NULL.