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.
commit ac97fad727f7ebcba2d2b345d95867331042a4af
Author: Jason Merrill <ja...@redhat.com>
Date:   Wed Mar 14 17:25:54 2018 -0400

            Core issue 2310 - conversion to base of incomplete type.
    
            * class.c (build_base_path): Check COMPLETE_TYPE_P for source type.

diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 30323f0a9f6..4616d8d3036 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -370,6 +370,15 @@ build_base_path (enum tree_code code,
       goto indout;
     }
 
+  if (!COMPLETE_TYPE_P (probe))
+    {
+      if (complain & tf_error)
+	error ("cannot convert from %qT to base class %qT because %qT is "
+	       "incomplete", BINFO_TYPE (d_binfo), BINFO_TYPE (binfo),
+	       BINFO_TYPE (d_binfo));
+      return error_mark_node;
+    }
+
   /* If we're in an NSDMI, we don't have the full constructor context yet
      that we need for converting to a virtual base, so just build a stub
      CONVERT_EXPR and expand it later in bot_replace.  */
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-base6.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-base6.C
new file mode 100644
index 00000000000..849ac81db78
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-base6.C
@@ -0,0 +1,14 @@
+// CWG issue 2310
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+template<typename A, typename B> struct check_derived_from { 
+  static A a; 
+  static constexpr B *p = &a;	// { dg-error "" }
+  int ar[p-p+1];
+}; 
+struct W { int i; }; 
+struct Z : W
+{
+  check_derived_from<Z, W> cdf;
+};
commit ced9e2797a8d1484829d140ce0147cd2be4d2091
Author: Jason Merrill <ja...@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 "" }

Reply via email to