C++ PATCHes for core issue resolutions

Message ID CADzB+2mL5fxPYaVJc1eb7GFHMsHzpXnyvpdE2w3FsN2TCFOqcQ@mail.gmail.com
State New
Headers show
Series
  • C++ PATCHes for core issue resolutions
Related show

Commit Message

Jason Merrill May 10, 2018, 6:57 p.m.
2310: We were crashing on this testcase; the proposed resolution of
2310 clarifies that we should reject it.

2267: brace and paren initialization should have the same semantics here.

Tested x86_64-pc-linux-gnu, applying to trunk.

Patch

commit ced9e2797a8d1484829d140ce0147cd2be4d2091
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Mar 15 14:38:57 2018 -0400

            CWG 2267 - list-initialization of reference temporary
    
            * call.c (reference_binding): List-initializing a reference
            temporary is copy-list-initialization.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index d3ee152808a..30fe682e7b4 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -1560,12 +1560,10 @@  reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags,
 	      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:;
     }
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-ref-2267.C b/gcc/testsuite/g++.dg/cpp0x/initlist-ref-2267.C
new file mode 100644
index 00000000000..dfd735a5add
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist-ref-2267.C
@@ -0,0 +1,14 @@ 
+// 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 "" }