llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: None (term-est) <details> <summary>Changes</summary> The following snippet, ```c++ #include <cassert> #include <stdexcept> [[noreturn]] void foo() { throw std::runtime_error("Why...?"); } int main() { try { foo(); } catch (std::runtime_error const& ex) { (void)ex; } } ``` is diagnosed with `error: function 'foo' could be declared with attribute 'noreturn' [-Werror,-Wmissing-noreturn]` when compiled with clang_trunk using `-Werror=missing-noreturn` flag. See more at [godbolt](https://godbolt.org/z/5zMsev4as) AST shows ``` | `-CXX11NoReturnAttr 0x1896e81eb00 <line:2:20> Inherited noreturn |-FunctionDecl 0x1896e81ebd8 <line:10:14, col:46> col:19 used foo 'void ()' | |-CompoundStmt 0x1896e81ee20 <col:25, col:46> | | `-CXXThrowExpr 0x1896e81ee08 <col:27, col:43> 'void' | | `-ImplicitCastExpr 0x1896e81edf0 <col:33, col:43> 'const char *' <ArrayToPointerDecay> | | `-ParenExpr 0x1896e81eda0 <col:33, col:43> 'const char[8]' lvalue | | `-StringLiteral 0x1896e81ed80 <col:34> 'const char[8]' lvalue "Why...?" | |-CXX11NoReturnAttr 0x1896e81ec80 <col:3> noreturn | `-InferredNoReturnAttr 0x1896e81ee38 <<invalid sloc>> Implicit ``` but the responsible code only checks for `NoReturnAttr`, adding a check for `CXX11NoReturnAttr` before emitting the diagnostic should fix this issue. --- Full diff: https://github.com/llvm/llvm-project/pull/148695.diff 1 Files Affected: - (modified) clang/lib/Sema/SemaDeclAttr.cpp (+1-1) ``````````diff diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 099207727c8c8..6d0a5d71d49ff 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -1976,7 +1976,7 @@ void clang::inferNoReturnAttr(Sema &S, const Decl *D) { Diags.isIgnored(diag::warn_suggest_noreturn_function, FD->getLocation())) return; - if (!FD->hasAttr<NoReturnAttr>() && !FD->hasAttr<InferredNoReturnAttr>() && + if (!FD->hasAttr<NoReturnAttr>() && !FD->hasAttr<CXX11NoReturnAttr>() && !FD->hasAttr<InferredNoReturnAttr>() && isKnownToAlwaysThrow(FD)) { NonConstFD->addAttr(InferredNoReturnAttr::CreateImplicit(S.Context)); `````````` </details> https://github.com/llvm/llvm-project/pull/148695 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits