================ @@ -2554,16 +2554,27 @@ Decl *Parser::ParseDeclarationAfterDeclarator( return ParseDeclarationAfterDeclaratorAndAttributes(D, TemplateInfo); } +static bool isConstexprVariable(const Decl *D) { + if (const VarDecl *Var = dyn_cast_if_present<VarDecl>(D)) + return Var->isConstexpr(); + + return false; +} + Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes( Declarator &D, const ParsedTemplateInfo &TemplateInfo, ForRangeInit *FRI) { // RAII type used to track whether we're inside an initializer. struct InitializerScopeRAII { Parser &P; Declarator &D; Decl *ThisDecl; + EnterExpressionEvaluationContext EC; InitializerScopeRAII(Parser &P, Declarator &D, Decl *ThisDecl) - : P(P), D(D), ThisDecl(ThisDecl) { + : P(P), D(D), ThisDecl(ThisDecl), + EC(P.Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated, + ThisDecl, Sema::ExpressionEvaluationContextRecord::EK_Other, + isConstexprVariable(ThisDecl)) { ---------------- efriedma-quic wrote:
On a side-note, gcc currently accepts the following; if I'm understanding the rule, it's not supposed to be valid. ``` struct S { int *value; constexpr S(int v) : value(new int {v}) {} constexpr ~S() { delete value; } }; consteval S fn() { return S(5); } int g(); void f() { int a = *fn().value; } ``` https://github.com/llvm/llvm-project/pull/89565 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits