| 1 |
.. title:: clang-tidy - modernize-use-nullptr |
| 2 |
|
| 3 |
modernize-use-nullptr |
| 4 |
===================== |
| 5 |
|
| 6 |
The check converts the usage of null pointer constants (e.g. ``NULL``, ``0``) |
| 7 |
to use the new C++11 and C23 ``nullptr`` keyword. |
| 8 |
|
| 9 |
Example |
| 10 |
------- |
| 11 |
|
| 12 |
.. code-block:: c++ |
| 13 |
|
| 14 |
void assignment() { |
| 15 |
char *a = NULL; |
| 16 |
char *b = 0; |
| 17 |
char c = 0; |
| 18 |
} |
| 19 |
|
| 20 |
int *ret_ptr() { |
| 21 |
return 0; |
| 22 |
} |
| 23 |
|
| 24 |
|
| 25 |
transforms to: |
| 26 |
|
| 27 |
.. code-block:: c++ |
| 28 |
|
| 29 |
void assignment() { |
| 30 |
char *a = nullptr; |
| 31 |
char *b = nullptr; |
| 32 |
char c = 0; |
| 33 |
} |
| 34 |
|
| 35 |
int *ret_ptr() { |
| 36 |
return nullptr; |
| 37 |
} |
| 38 |
|
| 39 |
Options |
| 40 |
------- |
| 41 |
|
| 42 |
.. option:: IgnoredTypes |
| 43 |
|
| 44 |
Semicolon-separated list of regular expressions to match pointer types for |
| 45 |
which implicit casts will be ignored. Default value: |
| 46 |
`std::_CmpUnspecifiedParam::;^std::__cmp_cat::__unspec`. |
| 47 |
|
| 48 |
.. option:: NullMacros |
| 49 |
|
| 50 |
Comma-separated list of macro names that will be transformed along with |
| 51 |
``NULL``. By default this check will only replace the ``NULL`` macro and will |
| 52 |
skip any similar user-defined macros. |
| 53 |
|
| 54 |
Example |
| 55 |
^^^^^^^ |
| 56 |
|
| 57 |
.. code-block:: c++ |
| 58 |
|
| 59 |
#define MY_NULL (void*)0 |
| 60 |
void assignment() { |
| 61 |
void *p = MY_NULL; |
| 62 |
} |
| 63 |
|
| 64 |
transforms to: |
| 65 |
|
| 66 |
.. code-block:: c++ |
| 67 |
|
| 68 |
#define MY_NULL NULL |
| 69 |
void assignment() { |
| 70 |
int *p = nullptr; |
| 71 |
} |
| 72 |
|
| 73 |
if the :option:`NullMacros` option is set to ``MY_NULL``. |