Allow users to specify NULL like macros to be replaced
-use-nullptr only replaced macro named NULL and ignored any user defined
macros that behaved like NULL. This patch introduces -user-null-macros
command line option to let users specify their custom NULL like macros.
- Added a -user-null-macros command line option that takes a
comma-separated list of user-defined macros to be replaced when using
the -use-nullptr transform.
- Added documentation.
- Updated testcase to reflect current behavior.
- Whitespace fixes.
Reviewers: revane, klimek, gribozavr
llvm-svn: 178243
diff --git a/clang-tools-extra/docs/UseNullptrTransform.rst b/clang-tools-extra/docs/UseNullptrTransform.rst
index 300caed..bc6289c 100644
--- a/clang-tools-extra/docs/UseNullptrTransform.rst
+++ b/clang-tools-extra/docs/UseNullptrTransform.rst
@@ -38,3 +38,45 @@
int *ret_ptr() {
return nullptr;
}
+
+
+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
+
+ cpp11-migrate -use-nullptr -user-null-macros=MY_NULL foo.cpp
+
+
+transforms to:
+
+.. code-block:: c++
+
+ #define MY_NULL NULL
+ void assignment() {
+ int *p = nullptr;
+ }
+
+
+Risk
+====
+
+:option:`-risk` has no effect in this transform.
diff --git a/clang-tools-extra/docs/cpp11-migrate.rst b/clang-tools-extra/docs/cpp11-migrate.rst
index 9d11f12..6e787f2 100644
--- a/clang-tools-extra/docs/cpp11-migrate.rst
+++ b/clang-tools-extra/docs/cpp11-migrate.rst
@@ -40,6 +40,12 @@
Makes use of the new C++11 keyword ``nullptr`` where possible.
See :doc:`UseNullptrTransform`.
+.. option:: -user-null-macros=<string>
+
+ ``<string>`` is a comma-separated list of user-defined macros that behave like
+ the ``NULL`` macro. The :option:`-use-nullptr` transform will replace these
+ macros along with ``NULL``. See :doc:`UseNullptrTransform`.
+
.. option:: -use-auto
Replace the type specifier of variable declarations with the ``auto`` type
@@ -76,7 +82,7 @@
:ref:`transform documentation <transforms>` for details.
.. option:: -final-syntax-check
-
+
After applying the final transform to a file, parse the file to ensure the
last transform did not introduce syntax errors. Syntax errors introduced by
earlier transforms are already caught when subsequent transforms parse the