[clang] Consider aggregate bases when checking if an InitListExpr is constant (PR #80519)
Reid Kleckner via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 5 16:25:19 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}}
----------------
rnk wrote:
I went ahead and make a targeted unit test for `isConstantInitializer` to see if that is nicer
https://github.com/llvm/llvm-project/pull/80519
More information about the cfe-commits
mailing list