-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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 1 commit
86029ca
b969ec1
80b072e
ca92bd0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Compound literals initializer-list should be a constant expression if it is defined outside the body of a function. Emit error instead of falling through tripping assertion error. fixes #139160
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -7245,6 +7245,17 @@ Sema::BuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, | |||||
if (auto ILE = dyn_cast<InitListExpr>(LiteralExpr)) | ||||||
for (unsigned i = 0, j = ILE->getNumInits(); i != j; i++) { | ||||||
Expr *Init = ILE->getInit(i); | ||||||
// 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 (!Init->isTypeDependent() && !Init->isValueDependent() && | ||||||
!Init->getType()->isDependentType()) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you need the check for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You're absolutely right—I just removed that check. Thanks! |
||||||
if (!Init->isConstantInitializer(Context, false)) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A code style nit, we try to add comments explaining the values with parameter name
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done, thanks. |
||||||
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?