[clang] Don't wrap immediate invocations in ConstantExprs within constexpr initializers (PR #89565)
Daniel M. Katz via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 29 07:15:00 PDT 2024
================
@@ -18573,25 +18562,35 @@ void Sema::ActOnCXXEnterDeclInitializer(Scope *S, Decl *D) {
if (S && D->isOutOfLine())
EnterDeclaratorContext(S, D->getDeclContext());
- // If we are parsing the initializer for a static data member, push a
- // new expression evaluation context that is associated with this static
- // data member.
- if (isNonlocalVariable(D))
- PushExpressionEvaluationContext(
- ExpressionEvaluationContext::PotentiallyEvaluated, D);
+ PushExpressionEvaluationContext(
+ ExpressionEvaluationContext::PotentiallyEvaluated, D);
}
/// Invoked after we are finished parsing an initializer for the declaration D.
void Sema::ActOnCXXExitDeclInitializer(Scope *S, Decl *D) {
- // If there is no declaration, there was an error parsing it.
- if (!D || D->isInvalidDecl())
- return;
-
- if (isNonlocalVariable(D))
- PopExpressionEvaluationContext();
+ assert(D);
if (S && D->isOutOfLine())
ExitDeclaratorContext(S);
+
+ if (getLangOpts().CPlusPlus23) {
+ // An expression or conversion is 'manifestly constant-evaluated' if it is:
+ // [...]
+ // - the initializer of a variable that is usable in constant expressions or
+ // has constant initialization.
+ if (auto *VD = dyn_cast<VarDecl>(D);
+ VD && (VD->isUsableInConstantExpressions(Context) ||
+ VD->hasConstantInitialization())) {
+ // An expression or conversion is in an 'immediate function context' if it
+ // is potentially evaluated and either:
+ // [...]
+ // - it is a subexpression of a manifestly constant-evaluated expression
+ // or conversion.
+ ExprEvalContexts.back().InImmediateFunctionContext = true;
+ }
+ }
+
+ PopExpressionEvaluationContext();
----------------
katzdm wrote:
I've added a clarifying comment - let me know if you think it's sufficient.
https://github.com/llvm/llvm-project/pull/89565
More information about the cfe-commits
mailing list