Author: Aiden Grossman
Date: 2026-10-20T21:16:49-07:00
New Revision: eaa62f5e2fcaad8cf6795403fa5c6b6a70fddb57

URL: 
https://github.com/llvm/llvm-project/commit/eaa62f5e2fcaad8cf6795403fa5c6b6a70fddb57
DIFF: 
https://github.com/llvm/llvm-project/commit/eaa62f5e2fcaad8cf6795403fa5c6b6a70fddb57.diff

LOG: [clang-tidy] Allow use of decltype(nullptr) for defining nullptr_t 
(#231637)

Otherwise we end up emitting a warning when trying to compile libc++
given it defines std::nullptr_t (and ::nullptr_t in stddef.h). It
doesn't make sense to emit this warning inside of the standard library
and the fix also ends up being circular.

Assisted-By: LLM

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
    clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-t.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
index 42a16c8739808..9a423ffd7013e 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
@@ -93,7 +93,9 @@ void UseNullptrCheck::registerMatchers(MatchFinder *Finder) {
       this);
 
   if (UseNullptrT)
-    Finder->addMatcher(typeLoc(loc(decltypeType(decltypeTypeNullptrLiteral())))
+    Finder->addMatcher(typeLoc(loc(decltypeType(decltypeTypeNullptrLiteral())),
+                               unless(hasParent(typedefNameDecl(hasAnyName(
+                                   "::nullptr_t", "::std::nullptr_t")))))
                            .bind("matchDecltypeNullptr"),
                        this);
 }

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-t.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-t.cpp
index ccee775f4b55a..14ed56a8a926a 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-t.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-t.cpp
@@ -18,3 +18,15 @@ template<class T=decltype(nullptr)>
 struct bar {};
 // CHECK-MESSAGES: :[[@LINE-2]]:18: warning: use std::nullptr_t instead
 // CHECK-FIXES: template<class T=std::nullptr_t>
+
+typedef decltype(nullptr) nullptr_t;
+
+namespace std {
+inline namespace __1 {
+using nullptr_t = decltype(nullptr);
+} // namespace __1
+} // namespace std
+
+using my_nullptr_t = decltype(nullptr);
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: use std::nullptr_t instead
+// CHECK-FIXES: using my_nullptr_t = std::nullptr_t;


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to