2015-12-23 01:36:49 +08:00
|
|
|
.. title:: clang-tidy - modernize-use-nullptr
|
|
|
|
|
2015-08-28 02:10:07 +08:00
|
|
|
modernize-use-nullptr
|
|
|
|
=====================
|
|
|
|
|
2015-09-18 22:08:57 +08:00
|
|
|
The check converts the usage of null pointer constants (eg. ``NULL``, ``0``)
|
|
|
|
to use the new C++11 ``nullptr`` keyword.
|
2015-08-28 02:10:07 +08:00
|
|
|
|
2015-09-18 22:08:57 +08:00
|
|
|
Example
|
2015-09-21 20:13:27 +08:00
|
|
|
-------
|
2015-09-18 22:08:57 +08:00
|
|
|
|
|
|
|
.. code-block:: c++
|
|
|
|
|
|
|
|
void assignment() {
|
|
|
|
char *a = NULL;
|
|
|
|
char *b = 0;
|
|
|
|
char c = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int *ret_ptr() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
transforms to:
|
|
|
|
|
|
|
|
.. code-block:: c++
|
|
|
|
|
|
|
|
void assignment() {
|
|
|
|
char *a = nullptr;
|
|
|
|
char *b = nullptr;
|
|
|
|
char c = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int *ret_ptr() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-08-18 19:06:09 +08:00
|
|
|
Options
|
|
|
|
-------
|
2015-09-18 22:08:57 +08:00
|
|
|
|
2017-03-04 22:06:26 +08:00
|
|
|
.. option:: NullMacros
|
2015-09-18 22:08:57 +08:00
|
|
|
|
2016-08-23 01:19:23 +08:00
|
|
|
Comma-separated list of macro names that will be transformed along with
|
|
|
|
``NULL``. By default this check will only replace the ``NULL`` macro and will
|
|
|
|
skip any similar user-defined macros.
|
2015-09-18 22:08:57 +08:00
|
|
|
|
|
|
|
Example
|
2015-09-21 20:13:27 +08:00
|
|
|
^^^^^^^
|
2015-09-18 22:08:57 +08:00
|
|
|
|
|
|
|
.. code-block:: c++
|
|
|
|
|
|
|
|
#define MY_NULL (void*)0
|
|
|
|
void assignment() {
|
|
|
|
void *p = MY_NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
transforms to:
|
|
|
|
|
|
|
|
.. code-block:: c++
|
|
|
|
|
|
|
|
#define MY_NULL NULL
|
|
|
|
void assignment() {
|
|
|
|
int *p = nullptr;
|
|
|
|
}
|
|
|
|
|
2017-03-04 22:06:26 +08:00
|
|
|
if the :option:`NullMacros` option is set to ``MY_NULL``.
|