https://github.com/ChrisLee02 created https://github.com/llvm/llvm-project/pull/218256
Fixes #214291 >From a11b575b9f8c28b6b87fd6e3f7c861790d4df286 Mon Sep 17 00:00:00 2001 From: Chrislee02 <[email protected]> Date: Mon, 24 Aug 2026 01:02:39 +0900 Subject: [PATCH] [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] +}; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
