-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[C23] Fix compound literals within function prototype #132097
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
7882bfb
68a7a74
168af58
b6ef700
f89a438
7729ed9
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 |
|---|---|---|
|
|
@@ -849,13 +849,11 @@ namespace CompoundLiterals { | |
| } | ||
| static_assert(get5() == 5, ""); | ||
|
|
||
| constexpr int get6(int f = (int[]){1,2,6}[2]) { // ref-note {{subexpression not valid in a constant expression}} \ | ||
| // ref-note {{declared here}} | ||
| constexpr int get6(int f = (int[]){1,2,6}[2]) { | ||
|
Collaborator
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. Maybe also worth testing a few more interactions with C++ constexpr:
Collaborator
Author
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. Thanks, I'll add more tests.
Yes, this should fail (and it does).
You are a bad person who should feel bad. :-D I do think that should evaluate to 1 (but only when calling which does behave how you'd expect. The VLA example says
Collaborator
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. With the VLA example, there are a few different weird interactions here... but the primary silly thing I'm doing is abusing VLAs to modify argument values. So, for example: On top of that, we have to consider the question of the lifetime of compound literals defined inside the array bound. But maybe we should just reject this sort of thing in C++ more aggressively, like gcc does, so we don't have to figure out all these weird cases.
Collaborator
Author
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.
Yeah, which we already seem to get wrong: https://godbolt.org/z/Y4xEGWhM3
I think that's what
I tend to agree we should be far more restrictive with VLAs in C++ than we are today. But I also think that's a different PR than this one. WDYT? |
||
| return f; | ||
| } | ||
| static_assert(get6(6) == 6, ""); | ||
| // FIXME: Who's right here? | ||
| static_assert(get6() == 6, ""); // ref-error {{not an integral constant expression}} | ||
| static_assert(get6() == 6, ""); | ||
|
|
||
| constexpr int x = (int){3}; | ||
| static_assert(x == 3, ""); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.