2018-05-09 Jason Merrill <jason@redhat.com>
+ CWG 2267 - list-initialization of reference temporary
+ * call.c (reference_binding): List-initializing a reference
+ temporary is copy-list-initialization.
+
* parser.c (cp_parser_class_head): Use num_template_headers_for_class.
* pt.c (instantiate_decl): Make sure we aren't trying to do a nested
goto skip;
}
}
- /* Otherwise, if T is a reference type, a prvalue temporary of the
- type referenced by T is copy-list-initialized or
- direct-list-initialized, depending on the kind of initialization
- for the reference, and the reference is bound to that temporary. */
- conv = implicit_conversion (to, from, expr, c_cast_p,
- flags|LOOKUP_NO_TEMP_BIND, complain);
+ /* Otherwise, if T is a reference type, a prvalue temporary of the type
+ referenced by T is copy-list-initialized, and the reference is bound
+ to that temporary. */
+ CONSTRUCTOR_IS_DIRECT_INIT (expr) = false;
skip:;
}
--- /dev/null
+// CWG 2267
+// { dg-do compile { target c++11 } }
+
+struct A {} a;
+struct B { explicit B(const A&); };
+B b1(a); // #1, ok
+const B &b2{a}; // { dg-error "" }
+const B &b3(a); // { dg-error "" }
+
+struct D { D(); };
+struct C { explicit operator D(); } c;
+D d1(c); // ok
+const D &d2{c}; // { dg-error "" }
+const D &d3(c); // { dg-error "" }