llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Oleksandr T. (a-tarasyuk) <details> <summary>Changes</summary> Fixes #<!-- -->63009 --- Full diff: https://github.com/llvm/llvm-project/pull/115558.diff 3 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+2) - (modified) clang/lib/Analysis/CFG.cpp (+10-5) - (modified) clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp (+12) ``````````diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index c3424e0e6f34c9..11d0e35d12a786 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -527,6 +527,8 @@ Improvements to Clang's diagnostics - Clang now diagnoses ``[[deprecated]]`` attribute usage on local variables (#GH90073). +- Clang now omits warnings for constructors marked with the ``[[noreturn]]`` attribute (#GH63009). + Improvements to Clang's time-trace ---------------------------------- diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp index f678ac6f2ff36a..4d83f04c23060a 100644 --- a/clang/lib/Analysis/CFG.cpp +++ b/clang/lib/Analysis/CFG.cpp @@ -4889,16 +4889,21 @@ CFGBlock *CFGBuilder::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E, return Visit(E->getSubExpr(), asc); } -CFGBlock *CFGBuilder::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *C, +CFGBlock *CFGBuilder::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E, AddStmtChoice asc) { // If the constructor takes objects as arguments by value, we need to properly // construct these objects. Construction contexts we find here aren't for the // constructor C, they're for its arguments only. - findConstructionContextsForArguments(C); + findConstructionContextsForArguments(E); - autoCreateBlock(); - appendConstructor(Block, C); - return VisitChildren(C); + CXXConstructorDecl *C = E->getConstructor(); + if (C && C->isNoReturn()) + Block = createNoReturnBlock(); + else + autoCreateBlock(); + + appendConstructor(Block, E); + return VisitChildren(E); } CFGBlock *CFGBuilder::VisitImplicitCastExpr(ImplicitCastExpr *E, diff --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp index 56920ea8e8cf20..a96224dd03e360 100644 --- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp +++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp @@ -49,3 +49,15 @@ void check() { test_type(g); test_type(h); // expected-note {{instantiation}} } + +namespace GH63009 { +struct S { + [[noreturn]] S() { throw int {}; } +}; + +int test_no_return_constructor() { S(); } // ok + +int main() { + test_no_return_constructor(); +} +} `````````` </details> https://github.com/llvm/llvm-project/pull/115558 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits