-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[clang] Compound Literal Statement Constant Expression Assertion Fix #139479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
86029ca
b969ec1
80b072e
ca92bd0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7241,10 +7241,21 @@ Sema::BuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, | |
| ? VK_PRValue | ||
| : VK_LValue; | ||
|
|
||
| // C99 6.5.2.5 | ||
| // "If the compound literal occurs outside the body of a function, the | ||
| // initializer list shall consist of constant expressions." | ||
| if (IsFileScope) | ||
| if (auto ILE = dyn_cast<InitListExpr>(LiteralExpr)) | ||
| for (unsigned i = 0, j = ILE->getNumInits(); i != j; i++) { | ||
| Expr *Init = ILE->getInit(i); | ||
| if (!Init->isTypeDependent() && !Init->isValueDependent() && | ||
| !Init->getType()->isDependentType()) | ||
|
||
| if (!Init->isConstantInitializer(Context, /*IsForRef=*/false)) { | ||
| Diag(Init->getExprLoc(), diag::err_init_element_not_constant) | ||
| << Init->getSourceBitField(); | ||
| return ExprError(); | ||
| } | ||
|
|
||
| ILE->setInit(i, ConstantExpr::Create(Context, Init)); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not checking for "outside of the function".
Note that GCC errors on these cases too https://compiler-explorer.com/z/TaqzEdnbe
I think you need to update the comment to better describe the check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a
if (IsFileScope)4 lines above.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have moved the comment to the
if (IsFileScope), is that alright?