https://github.com/boomanaiden154 created 
https://github.com/llvm/llvm-project/pull/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

>From b6a4f80a290badf02d2735099f902144be7f00b9 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <[email protected]>
Date: Tue, 13 Oct 2026 12:52:00 -0700
Subject: [PATCH] [clang-tidy] Allow use of decltype(nullptr) for defining
 nullptr_t

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
---
 .../clang-tidy/modernize/UseNullptrCheck.cpp         |  4 +++-
 .../clang-tidy/checkers/modernize/use-nullptr-t.cpp  | 12 ++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
index 42a16c87398083..9a423ffd7013e2 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 ccee775f4b55a9..14ed56a8a926a8 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