[clang-tools-extra] [clang-tidy] Allow use of decltype(nullptr) for defining nullptr_t (PR #231637)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 13 12:55:52 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra
Author: Aiden Grossman (boomanaiden154)
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/231637.diff
2 Files Affected:
- (modified) clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp (+3-1)
- (modified) clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-t.cpp (+12)
``````````diff
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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/231637
More information about the cfe-commits
mailing list