================
@@ -7669,32 +7776,48 @@ Sema::BuildCompoundLiteralExpr(SourceLocation
LParenLoc, TypeSourceInfo *TInfo,
return ExprError();
}
} else if (!literalType->isDependentType() &&
- RequireCompleteType(LParenLoc, literalType,
- diag::err_typecheck_decl_incomplete_type,
- SourceRange(LParenLoc, LiteralExpr->getSourceRange().getEnd())))
+ RequireCompleteType(
+ LParenLoc, literalType,
+ diag::err_typecheck_decl_incomplete_type,
+ SourceRange(LParenLoc,
+ LiteralExpr->getSourceRange().getEnd())))
return ExprError();
- InitializedEntity Entity
- = InitializedEntity::InitializeCompoundLiteralInit(TInfo);
- InitializationKind Kind
- = InitializationKind::CreateCStyleCast(LParenLoc,
- SourceRange(LParenLoc, RParenLoc),
- /*InitList=*/true);
+ InitializedEntity Entity = InitializedEntity::InitializeCompoundLiteralInit(
+ TInfo, literalType, ConstexprKind);
+ InitializationKind Kind = InitializationKind::CreateCStyleCast(
+ LParenLoc, SourceRange(LParenLoc, RParenLoc),
+ /*InitList=*/true);
InitializationSequence InitSeq(*this, Entity, Kind, LiteralExpr);
- ExprResult Result = InitSeq.Perform(*this, Entity, Kind, LiteralExpr,
- &literalType);
+ ExprResult Result =
+ InitSeq.Perform(*this, Entity, Kind, LiteralExpr, &literalType);
if (Result.isInvalid())
return ExprError();
LiteralExpr = Result.get();
- // We treat the compound literal as being at file scope if it's not in a
- // function or method body, or within the function's prototype scope. This
- // means the following compound literal is not at file scope:
- // void func(char *para[(int [1]){ 0 }[0]);
- const Scope *S = getCurScope();
- bool IsFileScope = !CurContext->isFunctionOrMethod() &&
- !S->isInCFunctionScope() &&
- (!S || !S->isFunctionPrototypeScope());
+ if (HasConstexpr && !LiteralExpr->isTypeDependent() &&
+ !LiteralExpr->isValueDependent() && !literalType->isDependentType()) {
+ SmallVector<PartialDiagnosticAt, 4> Notes;
+ SmallVector<PartialDiagnosticAt, 4> Warnings;
+ Expr::EvalResult Eval;
+ Eval.Diag = &Notes;
+ Eval.ExtendedDiag = &Warnings;
+ if (!LiteralExpr->EvaluateAsConstantExpr(Eval, Context) || !Notes.empty())
{
+ SourceLocation DiagLoc = ConstexprLoc;
+ if (Notes.size() == 1 && Notes.front().second.getDiagID() ==
+ diag::note_invalid_subexpr_in_const_expr) {
+ DiagLoc = Notes.front().first;
+ Notes.clear();
+ }
+ Diag(DiagLoc, diag::err_compound_literal_initializer_not_constant)
+ << LiteralExpr->getSourceRange();
+ for (const PartialDiagnosticAt &Note : Notes)
+ Diag(Note.first, Note.second);
+ return ExprError();
+ }
+ for (const PartialDiagnosticAt &Warning : Warnings)
+ Diag(Warning.first, Warning.second);
+ }
----------------
tbaederr wrote:
Why are we not wrapping a constexpr compound literal in a `ConstantExpr`?
https://github.com/llvm/llvm-project/pull/212559
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits