[clang-tools-extra] [clang-tidy] Fix modernize-use-noexcept crash on unparsed exception specs (PR #218256)
Hadong Lee via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 24 07:20:10 PDT 2026
https://github.com/ChrisLee02 updated https://github.com/llvm/llvm-project/pull/218256
>From a11b575b9f8c28b6b87fd6e3f7c861790d4df286 Mon Sep 17 00:00:00 2001
From: Chrislee02 <hdchris765 at snu.ac.kr>
Date: Mon, 24 Aug 2026 01:02:39 +0900
Subject: [PATCH 1/2] [clang-tidy] Fix modernize-use-noexcept crash on unparsed
exception specs
---
.../clang-tidy/modernize/UseNoexceptCheck.cpp | 3 ++-
.../use-noexcept-unparsed-exception-spec.cpp | 12 ++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
create mode 100644 clang-tools-extra/test/clang-tidy/checkers/modernize/use-noexcept-unparsed-exception-spec.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp
index 6bd5485abbac9..4641d56654e26 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp
@@ -76,7 +76,8 @@ void UseNoexceptCheck::check(const MatchFinder::MatchResult &Result) {
}
assert(FnTy && "FunctionProtoType is null.");
- if (isUnresolvedExceptionSpec(FnTy->getExceptionSpecType()))
+ if (FnTy->getExceptionSpecType() == EST_Unparsed ||
+ isUnresolvedExceptionSpec(FnTy->getExceptionSpecType()))
return;
assert(Range.isValid() && "Exception Source Range is invalid.");
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-noexcept-unparsed-exception-spec.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-noexcept-unparsed-exception-spec.cpp
new file mode 100644
index 0000000000000..b7967e8558ac5
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-noexcept-unparsed-exception-spec.cpp
@@ -0,0 +1,12 @@
+// RUN: %check_clang_tidy -std=c++11,c++14 -check-suffix=COMMON -expect-clang-tidy-error %s modernize-use-noexcept %t
+// RUN: %check_clang_tidy -std=c++17-or-later -check-suffixes=COMMON,CXX17 -expect-clang-tidy-error %s modernize-use-noexcept %t
+
+struct S {
+ template <typename T>
+ static void f() throw(typename T::X);
+ // CHECK-MESSAGES-CXX17: :[[@LINE-1]]:19: error: ISO C++17 does not allow dynamic exception specifications [clang-diagnostic-dynamic-exception-spec]
+ // CHECK-MESSAGES-COMMON: :[[@LINE-2]]:19: warning: dynamic exception specification 'throw(typename T::X)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+
+ typedef decltype(f<S>()) X;
+ // CHECK-MESSAGES-COMMON: :[[@LINE-1]]:20: error: exception specification is not available until end of class definition [clang-diagnostic-error]
+};
>From 1f927ec1839dcf6ef8937837481fb57e45208387 Mon Sep 17 00:00:00 2001
From: Chrislee02 <hdchris765 at snu.ac.kr>
Date: Mon, 24 Aug 2026 23:19:53 +0900
Subject: [PATCH 2/2] [clang-tidy] Add release note
---
clang-tools-extra/docs/ReleaseNotes.md | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/clang-tools-extra/docs/ReleaseNotes.md b/clang-tools-extra/docs/ReleaseNotes.md
index 51dd99256ca69..2cef7a3c1ceca 100644
--- a/clang-tools-extra/docs/ReleaseNotes.md
+++ b/clang-tools-extra/docs/ReleaseNotes.md
@@ -168,6 +168,10 @@ infrastructure are described first, followed by tool-specific sections.
`std::initializer_list` constructor, as the braced form could select a
different constructor.
+- Fixed a crash in {doc}`modernize-use-noexcept
+ <clang-tidy/checks/modernize/use-noexcept>` when analyzing malformed template
+ code with an unparsed exception specification.
+
- 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
More information about the cfe-commits
mailing list