r347531 - A "constexpr" is evaluated in a constant context. Make sure this is reflected
Bill Wendling via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 25 18:10:53 PST 2018
Author: void
Date: Sun Nov 25 18:10:53 2018
New Revision: 347531
URL: http://llvm.org/viewvc/llvm-project?rev=347531&view=rev
Log:
A "constexpr" is evaluated in a constant context. Make sure this is reflected
if a __builtin_constant_p() is a part of a constexpr.
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=347531&r1=347530&r2=347531&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Sun Nov 25 18:10:53 2018
@@ -10882,6 +10882,7 @@ bool Expr::EvaluateAsInitializer(APValue
? EvalInfo::EM_ConstantExpression
: EvalInfo::EM_ConstantFold);
InitInfo.setEvaluatingDecl(VD, Value);
+ InitInfo.InConstantContext = true;
LValue LVal;
LVal.set(VD);
@@ -11544,6 +11545,7 @@ bool Expr::isPotentialConstantExpr(const
EvalInfo Info(FD->getASTContext(), Status,
EvalInfo::EM_PotentialConstantExpression);
+ Info.InConstantContext = true;
const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD);
const CXXRecordDecl *RD = MD ? MD->getParent()->getCanonicalDecl() : nullptr;
Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp?rev=347531&r1=347530&r2=347531&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp Sun Nov 25 18:10:53 2018
@@ -1122,3 +1122,11 @@ constexpr E e2 = E{0};
static_assert(e2.x != e2.y, "");
} // namespace IndirectFields
+
+constexpr bool __constant_string_p(const char *__s) {
+ while (__builtin_constant_p(*__s) && *__s)
+ __s++;
+ return __builtin_constant_p(*__s);
+}
+
+constexpr bool n = __constant_string_p("a");
More information about the cfe-commits
mailing list