re PR c++/46220 (Error: invalid covariant return type generated for incomplete class...
authorJason Merrill <jason@redhat.com>
Fri, 4 Mar 2011 15:17:55 +0000 (10:17 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 4 Mar 2011 15:17:55 +0000 (10:17 -0500)
PR c++/46220
* search.c (check_final_overrider): Allow pointer to same incomplete
class type with different cv-quals.

From-SVN: r170676

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

index 747457a193787de436dabcd09efe8126551ae978..ce4ade16a84d4c16c3ea7228d901fcdc099f4fea 100644 (file)
@@ -1,3 +1,9 @@
+2011-03-04  Jason Merrill  <jason@redhat.com>
+
+       PR c++/46220
+       * search.c (check_final_overrider): Allow pointer to same incomplete
+       class type with different cv-quals.
+
 2011-03-03  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/47974
index 188f0a56d5eca3e67bded3210b6ecadd9b487f20..07ec9efd336ada4a57a3f599eee43756629c67aa 100644 (file)
@@ -1835,11 +1835,17 @@ check_final_overrider (tree overrider, tree basefn)
 
       if (CLASS_TYPE_P (base_return) && CLASS_TYPE_P (over_return))
        {
-         tree binfo = lookup_base (over_return, base_return,
-                                   ba_check | ba_quiet, NULL);
+         /* Strictly speaking, the standard requires the return type to be
+            complete even if it only differs in cv-quals, but that seems
+            like a bug in the wording.  */
+         if (!same_type_ignoring_top_level_qualifiers_p (base_return, over_return))
+           {
+             tree binfo = lookup_base (over_return, base_return,
+                                       ba_check | ba_quiet, NULL);
 
-         if (!binfo)
-           fail = 1;
+             if (!binfo)
+               fail = 1;
+           }
        }
       else if (!pedantic
               && can_convert (TREE_TYPE (base_type), TREE_TYPE (over_type)))
index e49bd7953deaf6b7c5ce7e7223f075d6c5af782e..c56bea48f04b78277940a1201fb4cf9f3ccc5a61 100644 (file)
@@ -1,3 +1,7 @@
+2011-03-04  Jason Merrill  <jason@redhat.com>
+
+       * g++.dg/inherit/covariant19.C: New.
+
 2011-03-04  Richard Guenther  <rguenther@suse.de>
 
        PR middle-end/47968
diff --git a/gcc/testsuite/g++.dg/inherit/covariant19.C b/gcc/testsuite/g++.dg/inherit/covariant19.C
new file mode 100644 (file)
index 0000000..22c2b0e
--- /dev/null
@@ -0,0 +1,14 @@
+// PR c++/46220
+// According to the letter of the standard this is invalid,
+// but that seems like a bug.
+
+class Baz;
+class Foo {
+public:
+    virtual const Baz* getBaz() = 0;
+};
+class Bar : public Foo {
+public:
+    Baz* getBaz();
+};
+