&& !(init && BRACE_ENCLOSED_INITIALIZER_P (init)
&& CP_AGGREGATE_TYPE_P (type)
&& (CLASS_TYPE_P (type)
+ /* The call to build_aggr_init below could end up
+ calling build_vec_init, which may break when we
+ are processing a template. */
+ || processing_template_decl
|| !TYPE_NEEDS_CONSTRUCTING (type)
|| type_has_extended_temps (type))))
|| (DECL_DECOMPOSITION_P (decl) && TREE_CODE (type) == ARRAY_TYPE))
--- /dev/null
+// PR c++/104284
+// { dg-do compile { target c++14 } }
+// { dg-additional-options "-fchecking=2" }
+
+struct S {
+ char c{};
+};
+
+auto x1 = [](auto) { constexpr S s[]{{}}; };
+auto x2 = [](auto) { constexpr S s[]{{'a'}}; };
+#if __cpp_designated_initializers >= 201707L
+auto x3 = [](auto) { constexpr S s[]{{.c = 'a'}}; };
+#endif
+auto x4 = [](auto) { constexpr S s[]{'a'}; };
+auto x5 = [](auto) { constexpr S s[]{{{}}}; };
+
+template<class>
+constexpr void g ()
+{
+ constexpr S s1[]{{}};
+ static_assert(s1[0].c == '\0', "");
+ constexpr S s2[]{{'a'}};
+ static_assert(s2[0].c == 'a', "");
+#if __cpp_designated_initializers >= 201707L
+ constexpr S s3[]{{.c = 'a'}};
+ static_assert(s3[0].c == 'a', "");
+#endif
+ constexpr S s4[]{'a'};
+ static_assert(s4[0].c == 'a', "");
+ constexpr S s5[]{{{}}};
+ static_assert(s5[0].c == '\0', "");
+}
+
+static_assert ((g<int>(), true), "");
--- /dev/null
+// PR c++/104284
+// { dg-do compile { target c++14 } }
+// { dg-additional-options "-fchecking=2" }
+
+struct S {
+ char a;
+ constexpr S() : a{'a'} { }
+ constexpr S(char a_) : a{a_} { }
+};
+
+auto x1 = [](auto) { constexpr S s[]{{}}; };
+auto x2 = [](auto) { constexpr S s[]{{'a'}}; };
+auto x3 = [](auto) { constexpr S s[]{'a'}; };
+auto x4 = [](auto) { constexpr S s[]{{{}}}; };
+
+template<typename>
+constexpr void g()
+{
+ constexpr S s1[]{{}};
+ static_assert(s1[0].a == 'a', "");
+ constexpr S s2[]{{'a'}};
+ static_assert(s2[0].a == 'a', "");
+ constexpr S s3[]{'a'};
+ static_assert(s3[0].a == 'a', "");
+ constexpr S s4[]{{{}}};
+ static_assert(s4[0].a == '\0', "");
+}
+
+void
+f ()
+{
+ g<int>();
+}
--- /dev/null
+// PR c++/104284
+// { dg-do compile { target c++14 } }
+// { dg-additional-options "-fchecking=2" }
+// Like constexpr-104284.C, but the function template is not
+// constexpr. In that case, we were still calling build_vec_init
+// in a template, just not crashing.
+
+struct S {
+ char c{};
+};
+
+template<class>
+void g ()
+{
+ constexpr S s1[]{{}};
+ static_assert(s1[0].c == '\0', "");
+ constexpr S s2[]{{'a'}};
+ static_assert(s2[0].c == 'a', "");
+#if __cpp_designated_initializers >= 201707L
+ constexpr S s3[]{{.c = 'a'}};
+ static_assert(s3[0].c == 'a', "");
+#endif
+ constexpr S s4[]{'a'};
+ static_assert(s4[0].c == 'a', "");
+ constexpr S s5[]{{{}}};
+ static_assert(s5[0].c == '\0', "");
+}
+
+void
+f ()
+{
+ g<int>();
+}
--- /dev/null
+// PR c++/104284
+// { dg-do run { target c++14 } }
+// { dg-additional-options "-fchecking=2" }
+
+struct S {
+ char c{};
+};
+
+template<class>
+constexpr void g ()
+{
+ S s1[]{{}};
+ if (s1[0].c != '\0')
+ __builtin_abort ();
+ S s2[]{{'a'}};
+ if (s2[0].c != 'a')
+ __builtin_abort ();
+#if __cpp_designated_initializers >= 201707L
+ S s3[]{{.c = 'a'}};
+ if (s3[0].c != 'a')
+ __builtin_abort ();
+#endif
+ S s4[]{'a'};
+ if (s4[0].c != 'a')
+ __builtin_abort ();
+ S s5[]{{{}}};
+ if (s5[0].c != '\0')
+ __builtin_abort ();
+}
+
+int
+main ()
+{
+ g<int>();
+}