Core issue 2310 - conversion to base of incomplete type.
authorJason Merrill <jason@redhat.com>
Thu, 10 May 2018 18:57:55 +0000 (14:57 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 10 May 2018 18:57:55 +0000 (14:57 -0400)
* class.c (build_base_path): Check COMPLETE_TYPE_P for source type.

From-SVN: r260127

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/testsuite/g++.dg/cpp0x/constexpr-base6.C [new file with mode: 0644]

index e6223ae4dc397d13dd7f8e017f42670ed3718a38..2b9ceb29dcf795fcf8e7b62faa5d84c1efd0be72 100644 (file)
@@ -1,5 +1,8 @@
 2018-05-09  Jason Merrill  <jason@redhat.com>
 
+       Core issue 2310 - conversion to base of incomplete type.
+       * class.c (build_base_path): Check COMPLETE_TYPE_P for source type.
+
        CWG 2267 - list-initialization of reference temporary
        * call.c (reference_binding): List-initializing a reference
        temporary is copy-list-initialization.
index 30323f0a9f61a6da04943e16cb022aad5c3b5a54..4616d8d303651196c0abcb09561e12e6fb382583 100644 (file)
@@ -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 (file)
index 0000000..849ac81
--- /dev/null
@@ -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;
+};