Skip to content

Commit f63263a

Browse files
committed
[Clang] skip warnings for constructors marked with the [[noreturn]] attribute
1 parent fef4c8a commit f63263a

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,8 @@ Improvements to Clang's diagnostics
527527

528528
- Clang now diagnoses ``[[deprecated]]`` attribute usage on local variables (#GH90073).
529529

530+
- Clang now omits warnings for constructors marked with the ``[[noreturn]]`` attribute (#GH63009).
531+
530532
Improvements to Clang's time-trace
531533
----------------------------------
532534

clang/lib/Analysis/CFG.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4889,16 +4889,21 @@ CFGBlock *CFGBuilder::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E,
48894889
return Visit(E->getSubExpr(), asc);
48904890
}
48914891

4892-
CFGBlock *CFGBuilder::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *C,
4892+
CFGBlock *CFGBuilder::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E,
48934893
AddStmtChoice asc) {
48944894
// If the constructor takes objects as arguments by value, we need to properly
48954895
// construct these objects. Construction contexts we find here aren't for the
48964896
// constructor C, they're for its arguments only.
4897-
findConstructionContextsForArguments(C);
4897+
findConstructionContextsForArguments(E);
48984898

4899-
autoCreateBlock();
4900-
appendConstructor(Block, C);
4901-
return VisitChildren(C);
4899+
CXXConstructorDecl *C = E->getConstructor();
4900+
if (C && C->isNoReturn())
4901+
Block = createNoReturnBlock();
4902+
else
4903+
autoCreateBlock();
4904+
4905+
appendConstructor(Block, E);
4906+
return VisitChildren(E);
49024907
}
49034908

49044909
CFGBlock *CFGBuilder::VisitImplicitCastExpr(ImplicitCastExpr *E,

clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,15 @@ void check() {
4949
test_type(g);
5050
test_type(h); // expected-note {{instantiation}}
5151
}
52+
53+
namespace GH63009 {
54+
struct S {
55+
[[noreturn]] S() { throw int {}; }
56+
};
57+
58+
int test_no_return_constructor() { S(); } // ok
59+
60+
int main() {
61+
test_no_return_constructor();
62+
}
63+
}

0 commit comments

Comments
 (0)