if (any_strictly_viable (*candidates))
return;
}
+ else if (CONSTRUCTOR_IS_DESIGNATED_INIT (init_list)
+ && !CP_AGGREGATE_TYPE_P (totype))
+ {
+ if (complain & tf_error)
+ error ("designated initializers cannot be used with a "
+ "non-aggregate type %qT", totype);
+ return;
+ }
/* Expand the CONSTRUCTOR into a new argument vec. */
vec<tree, va_gc> *new_args;
instantiate_type (type, expr, complain);
else if (invalid_nonstatic_memfn_p (loc, expr, complain))
/* We gave an error. */;
+ else if (BRACE_ENCLOSED_INITIALIZER_P (expr)
+ && CONSTRUCTOR_IS_DESIGNATED_INIT (expr)
+ && !CP_AGGREGATE_TYPE_P (type))
+ error_at (loc, "designated initializers cannot be used with a "
+ "non-aggregate type %qT", type);
else
{
range_label_for_type_mismatch label (TREE_TYPE (expr), type);
int y = bar ({.real = 0, .imag = 1}); // { dg-error "cannot convert" }
int baz (std::initializer_list<int>);
-int z = baz ({.one = 1, .two = 2, .three = 3}); // { dg-error "could not convert" }
+int z = baz ({.one = 1, .two = 2, .three = 3}); // { dg-error "designated initializers" }
--- /dev/null
+// PR c++/95369
+// { dg-do compile { target c++20 } }
+
+struct S {
+ unsigned a;
+ unsigned b;
+ constexpr S(unsigned _a, unsigned _b) noexcept: a{_a}, b{_b} { }
+};
+
+template<S s> struct X { };
+void g(S);
+
+struct Z {
+ S s;
+ Z() : s{.a = 1, .b = 2} { } // { dg-error "designated initializers|no matching function" }
+};
+
+S
+f()
+{
+ X<{.a = 1, .b = 2}> x; // { dg-error "designated initializers" }
+ S s{ .a = 1, .b = 2 }; // { dg-error "designated initializers|no matching function" }
+ S s2 = { .a = 1, .b = 2 }; // { dg-error "designated initializers" }
+ S s3 = S{ .a = 1, .b = 2 }; // { dg-error "designated initializers|no matching function" }
+ g({.a = 1, .b = 2}); // { dg-error "designated initializers" }
+ g(S{.a = 1, .b = 2}); // { dg-error "designated initializers|no matching function" }
+ return {.a = 1, .b = 2}; // { dg-error "designated initializers" }
+}