/cp
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 5 Jul 2013 16:28:35 +0000 (16:28 +0000)
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 5 Jul 2013 16:28:35 +0000 (16:28 +0000)
2013-07-05  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/14263
* class.c (build_base_path): Improve diagnostic.

/testsuite
2013-07-05  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/14263
* g++.dg/inherit/virtual10.C: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@200718 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/inherit/virtual10.C [new file with mode: 0644]

index 3a0ba58..c45c8be 100644 (file)
@@ -1,3 +1,8 @@
+2013-07-05  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/14263
+       * class.c (build_base_path): Improve diagnostic.
+
 2013-07-04  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/38634
index bb2c3fe..e516632 100644 (file)
@@ -291,9 +291,31 @@ build_base_path (enum tree_code code,
   if (code == MINUS_EXPR && v_binfo)
     {
       if (complain & tf_error)
-       error ("cannot convert from base %qT to derived type %qT via "
-              "virtual base %qT", BINFO_TYPE (binfo), BINFO_TYPE (d_binfo),
-              BINFO_TYPE (v_binfo));
+       {
+         if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), BINFO_TYPE (v_binfo)))
+           {
+             if (want_pointer)
+               error ("cannot convert from pointer to base class %qT to "
+                      "pointer to derived class %qT because the base is "
+                      "virtual", BINFO_TYPE (binfo), BINFO_TYPE (d_binfo));
+             else
+               error ("cannot convert from base class %qT to derived "
+                      "class %qT because the base is virtual",
+                      BINFO_TYPE (binfo), BINFO_TYPE (d_binfo));
+           }         
+         else
+           {
+             if (want_pointer)
+               error ("cannot convert from pointer to base class %qT to "
+                      "pointer to derived class %qT via virtual base %qT",
+                      BINFO_TYPE (binfo), BINFO_TYPE (d_binfo),
+                      BINFO_TYPE (v_binfo));
+             else
+               error ("cannot convert from base class %qT to derived "
+                      "class %qT via virtual base %qT", BINFO_TYPE (binfo),
+                      BINFO_TYPE (d_binfo), BINFO_TYPE (v_binfo));
+           }
+       }
       return error_mark_node;
     }
 
index e032005..4124aa4 100644 (file)
@@ -1,3 +1,8 @@
+2013-07-05  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/14263
+       * g++.dg/inherit/virtual10.C: New.
+
 2013-07-04  Joern Rennecke <joern.rennecke@embecosm.com>
 
        PR c/57821
diff --git a/gcc/testsuite/g++.dg/inherit/virtual10.C b/gcc/testsuite/g++.dg/inherit/virtual10.C
new file mode 100644 (file)
index 0000000..4cb858b
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/14263
+
+struct A { };
+
+struct B : virtual A { };
+
+int main()
+{
+   A* p = new B;
+   B* q = static_cast<B*>(p);  // { dg-error "cannot convert from pointer to base class 'A' to pointer to derived class 'B' because the base is virtual" }
+}