[clang] 7ebcb7c - PR50641: Properly handle AttributedStmts when checking for a valid
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 6 15:13:43 PDT 2021
Author: Richard Smith
Date: 2021-10-06T15:13:05-07:00
New Revision: 7ebcb7ce78f6abb73c5a29e7c8b9dd360acb65bc
URL: https://github.com/llvm/llvm-project/commit/7ebcb7ce78f6abb73c5a29e7c8b9dd360acb65bc
DIFF: https://github.com/llvm/llvm-project/commit/7ebcb7ce78f6abb73c5a29e7c8b9dd360acb65bc.diff
LOG: PR50641: Properly handle AttributedStmts when checking for a valid
constexpr function body.
Added:
Modified:
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/SemaCXX/attr-likelihood.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 88af1f7556c2..b7f84eab2f7e 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -2050,6 +2050,13 @@ CheckConstexprFunctionStmt(Sema &SemaRef, const FunctionDecl *Dcl, Stmt *S,
ReturnStmts.push_back(S->getBeginLoc());
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: {
// C++1y allows compound-statements.
if (!Cxx1yLoc.isValid())
@@ -2064,11 +2071,6 @@ CheckConstexprFunctionStmt(Sema &SemaRef, const FunctionDecl *Dcl, Stmt *S,
return true;
}
- case Stmt::AttributedStmtClass:
- if (!Cxx1yLoc.isValid())
- Cxx1yLoc = S->getBeginLoc();
- return true;
-
case Stmt::IfStmtClass: {
// C++1y allows if-statements.
if (!Cxx1yLoc.isValid())
diff --git a/clang/test/SemaCXX/attr-likelihood.cpp b/clang/test/SemaCXX/attr-likelihood.cpp
index 03ba301251d7..f7503fed49b9 100644
--- a/clang/test/SemaCXX/attr-likelihood.cpp
+++ b/clang/test/SemaCXX/attr-likelihood.cpp
@@ -154,4 +154,9 @@ void o()
// expected-note {{conflicting attribute is here}}
}
}
+
+constexpr int constexpr_function() {
+ [[likely]] return 0;
+}
+static_assert(constexpr_function() == 0);
#endif
More information about the cfe-commits
mailing list