-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Consider aggregate bases when checking if an InitListExpr is constant #80519
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
6ab5ba3
c630eee
07b4bf0
b75febc
1975ac3
d74fc2f
d655762
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify -ast-dump %s > %t-11 | ||
// RUN: FileCheck --input-file=%t-11 %s | ||
// RUN: FileCheck --input-file=%t-11 %s --check-prefix=CHECK-CXX11 | ||
// RUN: %clang_cc1 -verify -std=c++17 %s | ||
|
||
// http://llvm.org/PR7905 | ||
namespace PR7905 { | ||
|
@@ -108,3 +109,22 @@ int computed_with_lambda = [] { | |
return result; | ||
}(); | ||
#endif | ||
|
||
#if __cplusplus >= 201703L | ||
namespace DynamicFileScopeLiteral { | ||
// This covers the case where we have a file-scope compound literal with a | ||
// non-constant initializer in C++. Previously, we had a bug where Clang forgot | ||
// to consider initializer list elements for bases. | ||
struct Empty {}; | ||
struct Foo : Empty { | ||
int x; | ||
int y; | ||
}; | ||
int f(); | ||
Foo o = (Foo){ | ||
{}, | ||
1, | ||
f() // expected-error {{initializer element is not a compile-time constant}} | ||
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. gcc accepts this: https://godbolt.org/z/enWrG56je Why do we believe this should be rejected? 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. That is correct and I did discover that in my testing, but I think fixing that goes beyond the scope of this patch. Clang currently rejects this case if you remove the empty base: https://godbolt.org/z/1x8hshM75 Adding support for non-constant compound literals at file scope requires codegen changes, and this is fixing a small bug to make more The real issue is that I couldn't find a better way to test 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 went ahead and make a targeted unit test for |
||
}; | ||
} | ||
#endif |
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.
Should we be checking
CPlusPlus17
here?Also I would like to see a standard quote in the comments. I know we are not doing this locally but these are really helpful and we should be doing this more consistently.