• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1.. title:: clang-tidy - modernize-use-nullptr
2
3modernize-use-nullptr
4=====================
5
6The check converts the usage of null pointer constants (eg. ``NULL``, ``0``)
7to use the new C++11 ``nullptr`` keyword.
8
9Example
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
25transforms 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
39Options
40-------
41
42.. option:: NullMacros
43
44   Comma-separated list of macro names that will be transformed along with
45   ``NULL``. By default this check will only replace the ``NULL`` macro and will
46   skip any similar user-defined macros.
47
48Example
49^^^^^^^
50
51.. code-block:: c++
52
53  #define MY_NULL (void*)0
54  void assignment() {
55    void *p = MY_NULL;
56  }
57
58transforms to:
59
60.. code-block:: c++
61
62  #define MY_NULL NULL
63  void assignment() {
64    int *p = nullptr;
65  }
66
67if the :option:`NullMacros` option is set to ``MY_NULL``.
68