PR50641: Properly handle AttributedStmts when checking for a valid

constexpr function body.
This commit is contained in:
Richard Smith 2021-10-06 13:12:20 -07:00
parent 1183d65b4d
commit 7ebcb7ce78
2 changed files with 12 additions and 5 deletions
clang

View File

@ -2050,6 +2050,13 @@ CheckConstexprFunctionStmt(Sema &SemaRef, const FunctionDecl *Dcl, Stmt *S,
ReturnStmts.push_back(S->getBeginLoc()); ReturnStmts.push_back(S->getBeginLoc());
return true; return true;
case Stmt::AttributedStmtClass:
// Attributes on a statement don't affect its formal kind and hence don't
// affect its validity in a constexpr function.
return CheckConstexprFunctionStmt(SemaRef, Dcl,
cast<AttributedStmt>(S)->getSubStmt(),
ReturnStmts, Cxx1yLoc, Cxx2aLoc, Kind);
case Stmt::CompoundStmtClass: { case Stmt::CompoundStmtClass: {
// C++1y allows compound-statements. // C++1y allows compound-statements.
if (!Cxx1yLoc.isValid()) if (!Cxx1yLoc.isValid())
@ -2064,11 +2071,6 @@ CheckConstexprFunctionStmt(Sema &SemaRef, const FunctionDecl *Dcl, Stmt *S,
return true; return true;
} }
case Stmt::AttributedStmtClass:
if (!Cxx1yLoc.isValid())
Cxx1yLoc = S->getBeginLoc();
return true;
case Stmt::IfStmtClass: { case Stmt::IfStmtClass: {
// C++1y allows if-statements. // C++1y allows if-statements.
if (!Cxx1yLoc.isValid()) if (!Cxx1yLoc.isValid())

View File

@ -154,4 +154,9 @@ void o()
// expected-note {{conflicting attribute is here}} // expected-note {{conflicting attribute is here}}
} }
} }
constexpr int constexpr_function() {
[[likely]] return 0;
}
static_assert(constexpr_function() == 0);
#endif #endif