2013-03-09 11:33:50 +08:00
|
|
|
.. index:: Use-Nullptr Transform
|
|
|
|
|
|
|
|
=====================
|
|
|
|
Use-Nullptr Transform
|
|
|
|
=====================
|
|
|
|
|
|
|
|
The Use-Nullptr Transform is a transformation to convert the usage of null
|
|
|
|
pointer constants (eg. ``NULL``, ``0``) to use the new C++11 ``nullptr``
|
|
|
|
keyword. The transform is enabled with the :option:`-use-nullptr` option of
|
2013-09-05 01:35:07 +08:00
|
|
|
:program:`clang-modernize`.
|
2013-03-09 11:33:50 +08:00
|
|
|
|
|
|
|
Example
|
|
|
|
=======
|
|
|
|
|
|
|
|
.. 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;
|
|
|
|
}
|
2013-03-29 00:06:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
User defined macros
|
|
|
|
===================
|
|
|
|
|
|
|
|
By default this transform will only replace the ``NULL`` macro and will skip any
|
|
|
|
user-defined macros that behaves like ``NULL``. The user can use the
|
|
|
|
:option:`-user-null-macros` option to specify a comma-separated list of macro
|
|
|
|
names that will be transformed along with ``NULL``.
|
|
|
|
|
|
|
|
Example
|
|
|
|
-------
|
|
|
|
|
|
|
|
.. code-block:: c++
|
|
|
|
|
|
|
|
#define MY_NULL (void*)0
|
|
|
|
void assignment() {
|
|
|
|
void *p = MY_NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
using the command-line
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2013-09-05 01:35:07 +08:00
|
|
|
clang-modernize -use-nullptr -user-null-macros=MY_NULL foo.cpp
|
2013-03-29 00:06:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
transforms to:
|
|
|
|
|
|
|
|
.. code-block:: c++
|
|
|
|
|
|
|
|
#define MY_NULL NULL
|
|
|
|
void assignment() {
|
|
|
|
int *p = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Risk
|
|
|
|
====
|
|
|
|
|
|
|
|
:option:`-risk` has no effect in this transform.
|