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

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 `isConstantInitializer` correct.

The real issue is that I couldn't find a better way to test 
`isConstantInitializer` that will be resilient to that future bug fix, and I'm 
not sure what to do about that.

https://github.com/llvm/llvm-project/pull/80519
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to