Skip to content
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,8 @@ Improvements to Clang's diagnostics
getS(); // Now diagnoses "Reason 2", previously diagnoses "Reason 1"
}

- Clang now omits warnings for constructors marked with the ``[[noreturn]]`` attribute (#GH63009).

Improvements to Clang's time-trace
----------------------------------

Expand Down
15 changes: 10 additions & 5 deletions clang/lib/Analysis/CFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Loading