[clang-tools-extra] [clang-tidy] modernize-use-nullptr matches "NULL" in templates (PR #109169)

Florian Mayer via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 19 10:57:54 PDT 2024


================
@@ -84,6 +84,28 @@ void test_macro_expansion4() {
 #undef MY_NULL
 }
 
+template <typename T> struct pear {
+  // If you say __null (or NULL), we assume that T will always be a pointer
+  // type, so we suggest replacing it with nullptr.
+  void f() { x = __null; }
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use nullptr [modernize-use-nullptr]
+  // CHECK-FIXES: x = nullptr;
+
+  // But if you say 0, we allow the possibility that T can be used with integral
+  // and pointer types, and "0" is an acceptable initializer (even if "{}" might
+  // be even better).
+  void g() { y = 0; }
----------------
fmayer wrote:

I would drop the FIXES one, because that could conceivably match something from a later test.

https://github.com/llvm/llvm-project/pull/109169


More information about the cfe-commits mailing list