[clang-tools-extra] [clang-tidy] Add detection of decltype(nullptr) => std::nullptr_t to modernize-use-nullptr (PR #224591)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 18 12:06:56 PDT 2026
https://github.com/serge-sans-paille updated https://github.com/llvm/llvm-project/pull/224591
>From bcc52f1caef544ac8cbd301a32dd6a998f9b7740 Mon Sep 17 00:00:00 2001
From: serge-sans-paille <sguelton at mozilla.com>
Date: Fri, 18 Sep 2026 11:54:00 +0200
Subject: [PATCH 1/4] [clang-tidy] Add detection of decltype(nullptr) =>
std::nullptr_t to modernize-use-nullptr
Hidden behind an option switch, but on by default.
---
.../clang-tidy/modernize/UseNullptrCheck.cpp | 36 ++++++++++++++++++-
.../clang-tidy/modernize/UseNullptrCheck.h | 5 +++
clang-tools-extra/docs/ReleaseNotes.md | 4 +++
.../checks/modernize/use-nullptr.rst | 15 ++++++++
.../checkers/modernize/use-nullptr-basic.cpp | 14 ++++++++
.../checkers/modernize/use-nullptr.cpp | 2 +-
6 files changed, 74 insertions(+), 2 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
index 4f561a1f10204..4b26af5836ba2 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
@@ -28,6 +28,12 @@ AST_MATCHER(Type, sugaredNullptrType) {
return false;
}
+AST_MATCHER(DecltypeType, decltypeTypeNullptrLiteral) {
+ if (const Expr *E = Node.getUnderlyingExpr())
+ return isa<CXXNullPtrLiteralExpr>(E);
+ return false;
+}
+
} // namespace
static constexpr char CastSequence[] = "sequence";
@@ -81,6 +87,11 @@ void UseNullptrCheck::registerMatchers(MatchFinder *Finder) {
// Skip defaulted comparison operators.
unless(hasAncestor(functionDecl(isDefaulted())))),
this);
+
+ if (NullptrCStddef)
+ Finder->addMatcher(typeLoc(loc(decltypeType(decltypeTypeNullptrLiteral())))
+ .bind("matchDecltypeNullptr"),
+ this);
}
static bool isReplaceableRange(SourceLocation StartLoc, SourceLocation EndLoc,
@@ -495,17 +506,40 @@ UseNullptrCheck::UseNullptrCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
NullMacrosStr(Options.get("NullMacros", "NULL")),
IgnoredTypes(utils::options::parseStringList(Options.get(
- "IgnoredTypes", "_CmpUnspecifiedParam;^std::__cmp_cat::__unspec"))) {
+ "IgnoredTypes", "_CmpUnspecifiedParam;^std::__cmp_cat::__unspec"))),
+ NullptrCStddef(Options.get("NullptrCStddef", true)),
+ IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
+ utils::IncludeSorter::IS_LLVM),
+ areDiagsSelfContained()) {
NullMacrosStr.split(NullMacros, ",");
}
+void UseNullptrCheck::registerPPCallbacks(const SourceManager &SM,
+ Preprocessor *PP,
+ Preprocessor *ModuleExpanderPP) {
+ IncludeInserter.registerPreprocessor(PP);
+}
+
void UseNullptrCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "NullMacros", NullMacrosStr);
Options.store(Opts, "IgnoredTypes",
utils::options::serializeStringList(IgnoredTypes));
+ Options.store(Opts, "IncludeStyle", IncludeInserter.getStyle());
+ Options.store(Opts, "NullptrCStddef", NullptrCStddef);
}
void UseNullptrCheck::check(const MatchFinder::MatchResult &Result) {
+ if (const auto *MatchedTypeLoc =
+ Result.Nodes.getNodeAs<TypeLoc>("matchDecltypeNullptr")) {
+ diag(MatchedTypeLoc->getBeginLoc(), "use std::nullptr_t instead")
+ << IncludeInserter.createIncludeInsertion(
+ Result.SourceManager->getFileID(MatchedTypeLoc->getBeginLoc()),
+ "<cstddef>")
+ << FixItHint::CreateReplacement(MatchedTypeLoc->getSourceRange(),
+ "std::nullptr_t");
+ return;
+ }
+
const auto *NullCast = Result.Nodes.getNodeAs<CastExpr>(CastSequence);
assert(NullCast && "Bad Callback. No node provided");
diff --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h
index 1caa07afe352a..18df06a346bd6 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h
@@ -10,6 +10,7 @@
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USENULLPTRCHECK_H
#include "../ClangTidyCheck.h"
+#include "../utils/IncludeInserter.h"
namespace clang::tidy::modernize {
@@ -19,6 +20,8 @@ class UseNullptrCheck : public ClangTidyCheck {
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus11 || LangOpts.C23;
}
+ void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+ Preprocessor *ModuleExpanderPP) override;
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
@@ -27,6 +30,8 @@ class UseNullptrCheck : public ClangTidyCheck {
const StringRef NullMacrosStr;
SmallVector<StringRef, 1> NullMacros;
std::vector<StringRef> IgnoredTypes;
+ const bool NullptrCStddef;
+ utils::IncludeInserter IncludeInserter;
};
} // namespace clang::tidy::modernize
diff --git a/clang-tools-extra/docs/ReleaseNotes.md b/clang-tools-extra/docs/ReleaseNotes.md
index b77d0b5f5b7ec..a910c9d656ba5 100644
--- a/clang-tools-extra/docs/ReleaseNotes.md
+++ b/clang-tools-extra/docs/ReleaseNotes.md
@@ -224,6 +224,10 @@ infrastructure are described first, followed by tool-specific sections.
<clang-tidy/checks/modernize/use-noexcept>` when analyzing malformed template
code with an unparsed exception specification.
+- Extend {doc}`modernize-use-nullptr
+ <clang-tidy/checks/modernize/use-nullptr>` to turn ``decltype(nullptr)`` into
+ ``std::nullptr_t`` from ``<cstdef>``.
+
- Improved {doc}`performance-inefficient-algorithm
<clang-tidy/checks/performance/inefficient-algorithm>` check to no longer
produce a fix with the container or the searched-for value missing, such as
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst
index 25e17fee0a3d6..4ad115b4e7e3b 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst
@@ -6,6 +6,9 @@ modernize-use-nullptr
The check converts the usage of null pointer constants (e.g. ``NULL``, ``0``)
to use the new C++11 and C23 ``nullptr`` keyword.
+It also replaces references to ``decltype(nullptr)`` with ``std::nullptr_t``
+from ``<cstdef>``.
+
Example
-------
@@ -21,11 +24,15 @@ Example
return 0;
}
+ void expect_null(decltype(nullptr));
+
transforms to:
.. code-block:: c++
+ #include <cstddef>
+
void assignment() {
char *a = nullptr;
char *b = nullptr;
@@ -36,6 +43,9 @@ transforms to:
return nullptr;
}
+ void expect_null(std::nullptr_t);
+
+
Options
-------
@@ -51,6 +61,11 @@ Options
``NULL``. By default this check will only replace the ``NULL`` macro and will
skip any similar user-defined macros.
+.. option:: NullptrCStddef
+
+ Boolean controlling wether we should replace ``decltype(nullptr)`` with the
+ type ``std::nullptr_t`` from ``cstddef``. Defaults to ``true``.
+
Example
^^^^^^^
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-basic.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-basic.cpp
index 7b92cbd9b7608..621ddfe3f60ec 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-basic.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-basic.cpp
@@ -292,3 +292,17 @@ template<typename T>
T *f2(T *a = NULL) {
return a ? a : NULL;
}
+
+void foo(decltype(nullptr));
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use std::nullptr_t instead
+// CHECK-FIXES: void foo(std::nullptr_t);
+void foo(const decltype(nullptr));
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use std::nullptr_t instead
+// CHECK-FIXES: void foo(const std::nullptr_t);
+decltype(nullptr) a;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use std::nullptr_t instead
+// CHECK-FIXES: std::nullptr_t a;
+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>
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp
index 0092a5cc9a47b..3d4b951ba9336 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp
@@ -1,5 +1,5 @@
// RUN: %check_clang_tidy %s modernize-use-nullptr %t -- \
-// RUN: -config="{CheckOptions: {modernize-use-nullptr.NullMacros: 'MY_NULL,NULL'}}"
+// RUN: -config="{CheckOptions: {modernize-use-nullptr.NullMacros: 'MY_NULL,NULL', modernize-use-nullptr.NullptrCStddef: false}}"
#include <cstddef>
>From fb0ca3480a10b08493ec3a0e03227e2cdd1b1471 Mon Sep 17 00:00:00 2001
From: serge-sans-paille <sguelton at mozilla.com>
Date: Fri, 18 Sep 2026 13:12:28 +0200
Subject: [PATCH 2/4] fixup! [clang-tidy] Add detection of decltype(nullptr) =>
std::nullptr_t to modernize-use-nullptr
---
.../clang-tidy/modernize/UseNullptrCheck.cpp | 6 +++---
.../clang-tidy/modernize/UseNullptrCheck.h | 2 +-
.../clang-tidy/checks/modernize/use-nullptr.rst | 11 ++++++++---
.../checkers/modernize/use-nullptr-basic.cpp | 14 --------------
.../checkers/modernize/use-nullptr-t.cpp | 17 +++++++++++++++++
.../checkers/modernize/use-nullptr.cpp | 2 +-
6 files changed, 30 insertions(+), 22 deletions(-)
create mode 100644 clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-t.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
index 4b26af5836ba2..e7783ef7006f3 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
@@ -88,7 +88,7 @@ void UseNullptrCheck::registerMatchers(MatchFinder *Finder) {
unless(hasAncestor(functionDecl(isDefaulted())))),
this);
- if (NullptrCStddef)
+ if (useNullptrt)
Finder->addMatcher(typeLoc(loc(decltypeType(decltypeTypeNullptrLiteral())))
.bind("matchDecltypeNullptr"),
this);
@@ -507,7 +507,7 @@ UseNullptrCheck::UseNullptrCheck(StringRef Name, ClangTidyContext *Context)
NullMacrosStr(Options.get("NullMacros", "NULL")),
IgnoredTypes(utils::options::parseStringList(Options.get(
"IgnoredTypes", "_CmpUnspecifiedParam;^std::__cmp_cat::__unspec"))),
- NullptrCStddef(Options.get("NullptrCStddef", true)),
+ useNullptrt(Options.get("useNullptrt", true)),
IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
utils::IncludeSorter::IS_LLVM),
areDiagsSelfContained()) {
@@ -525,7 +525,7 @@ void UseNullptrCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "IgnoredTypes",
utils::options::serializeStringList(IgnoredTypes));
Options.store(Opts, "IncludeStyle", IncludeInserter.getStyle());
- Options.store(Opts, "NullptrCStddef", NullptrCStddef);
+ Options.store(Opts, "useNullptrt", useNullptrt);
}
void UseNullptrCheck::check(const MatchFinder::MatchResult &Result) {
diff --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h
index 18df06a346bd6..2899ee44eba88 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h
@@ -30,7 +30,7 @@ class UseNullptrCheck : public ClangTidyCheck {
const StringRef NullMacrosStr;
SmallVector<StringRef, 1> NullMacros;
std::vector<StringRef> IgnoredTypes;
- const bool NullptrCStddef;
+ const bool useNullptrt;
utils::IncludeInserter IncludeInserter;
};
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst
index 4ad115b4e7e3b..173db2a604e25 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst
@@ -61,10 +61,15 @@ Options
``NULL``. By default this check will only replace the ``NULL`` macro and will
skip any similar user-defined macros.
-.. option:: NullptrCStddef
+.. option:: useNullptrt
- Boolean controlling wether we should replace ``decltype(nullptr)`` with the
- type ``std::nullptr_t`` from ``cstddef``. Defaults to ``true``.
+ Boolean controlling whether we should replace ``decltype(nullptr)`` with the
+ type ``std::nullptr_t`` from ``<cstddef>``. Defaults to ``true``.
+
+.. option:: IncludeStyle
+
+ A string specifying which include-style is used, `llvm` or `google`. Default
+ is `llvm`.
Example
^^^^^^^
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-basic.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-basic.cpp
index 621ddfe3f60ec..7b92cbd9b7608 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-basic.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-basic.cpp
@@ -292,17 +292,3 @@ template<typename T>
T *f2(T *a = NULL) {
return a ? a : NULL;
}
-
-void foo(decltype(nullptr));
-// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use std::nullptr_t instead
-// CHECK-FIXES: void foo(std::nullptr_t);
-void foo(const decltype(nullptr));
-// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use std::nullptr_t instead
-// CHECK-FIXES: void foo(const std::nullptr_t);
-decltype(nullptr) a;
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use std::nullptr_t instead
-// CHECK-FIXES: std::nullptr_t a;
-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>
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
new file mode 100644
index 0000000000000..d53f1c8b6594a
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-t.cpp
@@ -0,0 +1,17 @@
+// RUN: %check_clang_tidy %s modernize-use-nullptr %t -- -- -fno-delayed-template-parsing
+
+// CHECK-FIXES: #include <cstddef>
+
+void foo(decltype(nullptr));
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use std::nullptr_t instead
+// CHECK-FIXES: void foo(std::nullptr_t);
+void foo(const decltype(nullptr));
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use std::nullptr_t instead
+// CHECK-FIXES: void foo(const std::nullptr_t);
+decltype(nullptr) a;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use std::nullptr_t instead
+// CHECK-FIXES: std::nullptr_t a;
+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>
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp
index 3d4b951ba9336..72500ebd93293 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp
@@ -1,5 +1,5 @@
// RUN: %check_clang_tidy %s modernize-use-nullptr %t -- \
-// RUN: -config="{CheckOptions: {modernize-use-nullptr.NullMacros: 'MY_NULL,NULL', modernize-use-nullptr.NullptrCStddef: false}}"
+// RUN: -config="{CheckOptions: {modernize-use-nullptr.NullMacros: 'MY_NULL,NULL', modernize-use-nullptr.UseNullptrt: false}}"
#include <cstddef>
>From bdb72eacfdb9b876113473f1304f5f8288d827db Mon Sep 17 00:00:00 2001
From: serge-sans-paille <sguelton at mozilla.com>
Date: Fri, 18 Sep 2026 17:28:08 +0200
Subject: [PATCH 3/4] fixup! fixup! [clang-tidy] Add detection of
decltype(nullptr) => std::nullptr_t to modernize-use-nullptr
---
.../clang-tidy/modernize/UseNullptrCheck.cpp | 8 ++++----
clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h | 2 +-
.../docs/clang-tidy/checks/modernize/use-nullptr.rst | 2 +-
.../test/clang-tidy/checkers/modernize/use-nullptr-t.cpp | 3 +++
.../test/clang-tidy/checkers/modernize/use-nullptr.cpp | 2 +-
5 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
index e7783ef7006f3..086a93b1ccbbc 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
@@ -30,7 +30,7 @@ AST_MATCHER(Type, sugaredNullptrType) {
AST_MATCHER(DecltypeType, decltypeTypeNullptrLiteral) {
if (const Expr *E = Node.getUnderlyingExpr())
- return isa<CXXNullPtrLiteralExpr>(E);
+ return isa<CXXNullPtrLiteralExpr>(E->IgnoreParens());
return false;
}
@@ -88,7 +88,7 @@ void UseNullptrCheck::registerMatchers(MatchFinder *Finder) {
unless(hasAncestor(functionDecl(isDefaulted())))),
this);
- if (useNullptrt)
+ if (useNullptrT)
Finder->addMatcher(typeLoc(loc(decltypeType(decltypeTypeNullptrLiteral())))
.bind("matchDecltypeNullptr"),
this);
@@ -507,7 +507,7 @@ UseNullptrCheck::UseNullptrCheck(StringRef Name, ClangTidyContext *Context)
NullMacrosStr(Options.get("NullMacros", "NULL")),
IgnoredTypes(utils::options::parseStringList(Options.get(
"IgnoredTypes", "_CmpUnspecifiedParam;^std::__cmp_cat::__unspec"))),
- useNullptrt(Options.get("useNullptrt", true)),
+ useNullptrT(Options.get("useNullptrT", true)),
IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
utils::IncludeSorter::IS_LLVM),
areDiagsSelfContained()) {
@@ -525,7 +525,7 @@ void UseNullptrCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "IgnoredTypes",
utils::options::serializeStringList(IgnoredTypes));
Options.store(Opts, "IncludeStyle", IncludeInserter.getStyle());
- Options.store(Opts, "useNullptrt", useNullptrt);
+ Options.store(Opts, "useNullptrT", useNullptrT);
}
void UseNullptrCheck::check(const MatchFinder::MatchResult &Result) {
diff --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h
index 2899ee44eba88..3c224e6843b10 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h
@@ -30,7 +30,7 @@ class UseNullptrCheck : public ClangTidyCheck {
const StringRef NullMacrosStr;
SmallVector<StringRef, 1> NullMacros;
std::vector<StringRef> IgnoredTypes;
- const bool useNullptrt;
+ const bool useNullptrT;
utils::IncludeInserter IncludeInserter;
};
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst
index 173db2a604e25..2f7fdeeae33d6 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst
@@ -61,7 +61,7 @@ Options
``NULL``. By default this check will only replace the ``NULL`` macro and will
skip any similar user-defined macros.
-.. option:: useNullptrt
+.. option:: useNullptrT
Boolean controlling whether we should replace ``decltype(nullptr)`` with the
type ``std::nullptr_t`` from ``<cstddef>``. Defaults to ``true``.
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 d53f1c8b6594a..ccee775f4b55a 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
@@ -8,6 +8,9 @@ void foo(decltype(nullptr));
void foo(const decltype(nullptr));
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use std::nullptr_t instead
// CHECK-FIXES: void foo(const std::nullptr_t);
+void foo(decltype((nullptr))*);
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use std::nullptr_t instead
+// CHECK-FIXES: void foo(std::nullptr_t*);
decltype(nullptr) a;
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use std::nullptr_t instead
// CHECK-FIXES: std::nullptr_t a;
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp
index 72500ebd93293..309cb1823ff6d 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp
@@ -1,5 +1,5 @@
// RUN: %check_clang_tidy %s modernize-use-nullptr %t -- \
-// RUN: -config="{CheckOptions: {modernize-use-nullptr.NullMacros: 'MY_NULL,NULL', modernize-use-nullptr.UseNullptrt: false}}"
+// RUN: -config="{CheckOptions: {modernize-use-nullptr.NullMacros: 'MY_NULL,NULL', modernize-use-nullptr.UseNullptrT: false}}"
#include <cstddef>
>From fead00867dbfffa16e5154246a0bb1677e77e5b6 Mon Sep 17 00:00:00 2001
From: serge-sans-paille <sguelton at mozilla.com>
Date: Fri, 18 Sep 2026 21:06:30 +0200
Subject: [PATCH 4/4] fixup! fixup! fixup! [clang-tidy] Add detection of
decltype(nullptr) => std::nullptr_t to modernize-use-nullptr
---
clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp | 6 +++---
clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h | 2 +-
clang-tools-extra/docs/ReleaseNotes.md | 4 ++--
.../docs/clang-tidy/checks/modernize/use-nullptr.rst | 2 +-
4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
index 086a93b1ccbbc..01bb98cfbcfd4 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
@@ -88,7 +88,7 @@ void UseNullptrCheck::registerMatchers(MatchFinder *Finder) {
unless(hasAncestor(functionDecl(isDefaulted())))),
this);
- if (useNullptrT)
+ if (UseNullptrT)
Finder->addMatcher(typeLoc(loc(decltypeType(decltypeTypeNullptrLiteral())))
.bind("matchDecltypeNullptr"),
this);
@@ -507,7 +507,7 @@ UseNullptrCheck::UseNullptrCheck(StringRef Name, ClangTidyContext *Context)
NullMacrosStr(Options.get("NullMacros", "NULL")),
IgnoredTypes(utils::options::parseStringList(Options.get(
"IgnoredTypes", "_CmpUnspecifiedParam;^std::__cmp_cat::__unspec"))),
- useNullptrT(Options.get("useNullptrT", true)),
+ UseNullptrT(Options.get("UseNullptrT", true)),
IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
utils::IncludeSorter::IS_LLVM),
areDiagsSelfContained()) {
@@ -525,7 +525,7 @@ void UseNullptrCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "IgnoredTypes",
utils::options::serializeStringList(IgnoredTypes));
Options.store(Opts, "IncludeStyle", IncludeInserter.getStyle());
- Options.store(Opts, "useNullptrT", useNullptrT);
+ Options.store(Opts, "UseNullptrT", UseNullptrT);
}
void UseNullptrCheck::check(const MatchFinder::MatchResult &Result) {
diff --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h
index 3c224e6843b10..7f3eb6e4dd18b 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h
@@ -30,7 +30,7 @@ class UseNullptrCheck : public ClangTidyCheck {
const StringRef NullMacrosStr;
SmallVector<StringRef, 1> NullMacros;
std::vector<StringRef> IgnoredTypes;
- const bool useNullptrT;
+ const bool UseNullptrT;
utils::IncludeInserter IncludeInserter;
};
diff --git a/clang-tools-extra/docs/ReleaseNotes.md b/clang-tools-extra/docs/ReleaseNotes.md
index a910c9d656ba5..a9c4af5eec244 100644
--- a/clang-tools-extra/docs/ReleaseNotes.md
+++ b/clang-tools-extra/docs/ReleaseNotes.md
@@ -225,8 +225,8 @@ infrastructure are described first, followed by tool-specific sections.
code with an unparsed exception specification.
- Extend {doc}`modernize-use-nullptr
- <clang-tidy/checks/modernize/use-nullptr>` to turn ``decltype(nullptr)`` into
- ``std::nullptr_t`` from ``<cstdef>``.
+ <clang-tidy/checks/modernize/use-nullptr>` to turn `decltype(nullptr)` into
+ `std::nullptr_t` from `<cstdef>`.
- Improved {doc}`performance-inefficient-algorithm
<clang-tidy/checks/performance/inefficient-algorithm>` check to no longer
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst
index 2f7fdeeae33d6..ce43e1e4eb5dc 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst
@@ -61,7 +61,7 @@ Options
``NULL``. By default this check will only replace the ``NULL`` macro and will
skip any similar user-defined macros.
-.. option:: useNullptrT
+.. option:: UseNullptrT
Boolean controlling whether we should replace ``decltype(nullptr)`` with the
type ``std::nullptr_t`` from ``<cstddef>``. Defaults to ``true``.
More information about the cfe-commits
mailing list