[clang] Consider aggregate bases when checking if an InitListExpr is constant (PR #80519)

Shafik Yaghmour via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 2 18:30:27 PST 2024


================
@@ -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}}
----------------
shafik wrote:

gcc accepts this: https://godbolt.org/z/enWrG56je

Why do we believe this should be rejected?

https://github.com/llvm/llvm-project/pull/80519


More information about the cfe-commits mailing list