public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/46220] New: Error: invalid covariant return type generated for incomplete class type
@ 2010-10-28 23:10 nathan.keynes at oracle dot com
  2010-10-28 23:16 ` [Bug c++/46220] [4.3/4.4/4.5/4.6 Regression] Error: invalid covariant return type generated for incomplete class type and different qualifer pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: nathan.keynes at oracle dot com @ 2010-10-28 23:10 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46220

           Summary: Error: invalid covariant return type generated for
                    incomplete class type
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: nathan.keynes@oracle.com


g++ fails to compile the following test case:

class Baz;
class Foo {
public:
    virtual const Baz* getBaz() = 0;
};
class Bar : public Foo {
public:
    Baz* getBaz();
};

test-covar.cc:8: error: invalid covariant return type for ‘virtual Baz*
Bar::getBaz()’
test-covar.cc:4: error:   overriding ‘virtual const Baz* Foo::getBaz()’

However, it compiles successfully if Baz is complete:
class Baz { };
class Foo {
public:
    virtual const Baz* getBaz() = 0;
};
class Bar : public Foo {
public:
    Baz* getBaz();
};

Reproducible on x86_64-redhat-linux (4.1.2 and 4.4.0) and
i386-pc-solaris2.11 (4.2.4, 4.3.4 and 4.5.1). Works correctly with g++ 3.4.3


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/46220] [4.3/4.4/4.5/4.6 Regression] Error: invalid covariant return type generated for incomplete class type and different qualifer
  2010-10-28 23:10 [Bug c++/46220] New: Error: invalid covariant return type generated for incomplete class type nathan.keynes at oracle dot com
@ 2010-10-28 23:16 ` pinskia at gcc dot gnu.org
  2010-10-29  0:45 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2010-10-28 23:16 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46220

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2010.10.28 23:16:36
   Target Milestone|---                         |4.3.6
            Summary|Error: invalid covariant    |[4.3/4.4/4.5/4.6
                   |return type generated for   |Regression] Error: invalid
                   |incomplete class type and   |covariant return type
                   |different qualifer          |generated for incomplete
                   |                            |class type and different
                   |                            |qualifer
     Ever Confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2010-10-28 23:16:36 UTC ---
Confirmed, I don't see why this is a covariant return at all, the difference in
qualifier should not change anything.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/46220] [4.3/4.4/4.5/4.6 Regression] Error: invalid covariant return type generated for incomplete class type and different qualifer
  2010-10-28 23:10 [Bug c++/46220] New: Error: invalid covariant return type generated for incomplete class type nathan.keynes at oracle dot com
  2010-10-28 23:16 ` [Bug c++/46220] [4.3/4.4/4.5/4.6 Regression] Error: invalid covariant return type generated for incomplete class type and different qualifer pinskia at gcc dot gnu.org
@ 2010-10-29  0:45 ` redi at gcc dot gnu.org
  2010-10-29  0:51 ` redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2010-10-29  0:45 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46220

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-10-29 00:45:26 UTC ---
It certainly is a covariant return type, it meets the criteria in all three
bullet points of 10.3 [class.virtual] p5


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/46220] [4.3/4.4/4.5/4.6 Regression] Error: invalid covariant return type generated for incomplete class type and different qualifer
  2010-10-28 23:10 [Bug c++/46220] New: Error: invalid covariant return type generated for incomplete class type nathan.keynes at oracle dot com
  2010-10-28 23:16 ` [Bug c++/46220] [4.3/4.4/4.5/4.6 Regression] Error: invalid covariant return type generated for incomplete class type and different qualifer pinskia at gcc dot gnu.org
  2010-10-29  0:45 ` redi at gcc dot gnu.org
@ 2010-10-29  0:51 ` redi at gcc dot gnu.org
  2010-10-29  1:16 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2010-10-29  0:51 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46220

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-10-29 00:50:53 UTC ---
However p6 says

If the return type of D::f differs from the return type of B::f, the class type
in the return type of D::f shall be complete at the point of declaration of
D::f or shall be the class type D.

In this case the class type in the return of Bar::getBaz is neither complete,
nor Bar.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/46220] [4.3/4.4/4.5/4.6 Regression] Error: invalid covariant return type generated for incomplete class type and different qualifer
  2010-10-28 23:10 [Bug c++/46220] New: Error: invalid covariant return type generated for incomplete class type nathan.keynes at oracle dot com
                   ` (2 preceding siblings ...)
  2010-10-29  0:51 ` redi at gcc dot gnu.org
@ 2010-10-29  1:16 ` redi at gcc dot gnu.org
  2010-11-12 14:51 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2010-10-29  1:16 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46220

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-10-29 01:16:02 UTC ---
Jason, is there a reason to disallow covariant returns where the return type
only differs in cv-qualification of the class type?

Could the requirement for a complete type be incorporated into the second
bullet of p5, since it has to be complete for us to know it's an accessible
base?

Why does the third bullet of p5 talk about the cv-qualification of pointers and
references, when top-level cv-quals in return types are ignored, and references
have no cv-quals?  Is this an artefact of ARM-era C++?

Am I misreading the wording, or should I ask Mike to open an issue?


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/46220] [4.3/4.4/4.5/4.6 Regression] Error: invalid covariant return type generated for incomplete class type and different qualifer
  2010-10-28 23:10 [Bug c++/46220] New: Error: invalid covariant return type generated for incomplete class type nathan.keynes at oracle dot com
                   ` (3 preceding siblings ...)
  2010-10-29  1:16 ` redi at gcc dot gnu.org
@ 2010-11-12 14:51 ` rguenth at gcc dot gnu.org
  2011-03-03 20:52 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2010-11-12 14:51 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46220

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/46220] [4.3/4.4/4.5/4.6 Regression] Error: invalid covariant return type generated for incomplete class type and different qualifer
  2010-10-28 23:10 [Bug c++/46220] New: Error: invalid covariant return type generated for incomplete class type nathan.keynes at oracle dot com
                   ` (4 preceding siblings ...)
  2010-11-12 14:51 ` rguenth at gcc dot gnu.org
@ 2011-03-03 20:52 ` jason at gcc dot gnu.org
  2011-03-04 15:18 ` jason at gcc dot gnu.org
  2011-03-05 20:35 ` jason at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu.org @ 2011-03-03 20:52 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46220

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED

--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> 2011-03-03 20:52:00 UTC ---
(In reply to comment #4)
> Jason, is there a reason to disallow covariant returns where the return type
> only differs in cv-qualification of the class type?
> 
> Could the requirement for a complete type be incorporated into the second
> bullet of p5, since it has to be complete for us to know it's an accessible
> base?

Seems reasonable to me.  Or change "if the return type..." to "if the class in
the return type...". I note that EDG accepts the testcase.

> Why does the third bullet of p5 talk about the cv-qualification of pointers and
> references, when top-level cv-quals in return types are ignored, and references
> have no cv-quals?  Is this an artefact of ARM-era C++?

Top-level cv-quals are not ignored in return types, only in parameter types.

> Am I misreading the wording, or should I ask Mike to open an issue?

I think an issue to clarify this would be appropriate.  I'll go ahead and fix
the compiler.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/46220] [4.3/4.4/4.5/4.6 Regression] Error: invalid covariant return type generated for incomplete class type and different qualifer
  2010-10-28 23:10 [Bug c++/46220] New: Error: invalid covariant return type generated for incomplete class type nathan.keynes at oracle dot com
                   ` (5 preceding siblings ...)
  2011-03-03 20:52 ` jason at gcc dot gnu.org
@ 2011-03-04 15:18 ` jason at gcc dot gnu.org
  2011-03-05 20:35 ` jason at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu.org @ 2011-03-04 15:18 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46220

--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> 2011-03-04 15:18:03 UTC ---
Author: jason
Date: Fri Mar  4 15:17:55 2011
New Revision: 170676

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=170676
Log:
    PR c++/46220
    * search.c (check_final_overrider): Allow pointer to same incomplete
    class type with different cv-quals.

Added:
    trunk/gcc/testsuite/g++.dg/inherit/covariant19.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/search.c
    trunk/gcc/testsuite/ChangeLog


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/46220] [4.3/4.4/4.5/4.6 Regression] Error: invalid covariant return type generated for incomplete class type and different qualifer
  2010-10-28 23:10 [Bug c++/46220] New: Error: invalid covariant return type generated for incomplete class type nathan.keynes at oracle dot com
                   ` (6 preceding siblings ...)
  2011-03-04 15:18 ` jason at gcc dot gnu.org
@ 2011-03-05 20:35 ` jason at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu.org @ 2011-03-05 20:35 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46220

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|4.3.6                       |4.6.0

--- Comment #7 from Jason Merrill <jason at gcc dot gnu.org> 2011-03-05 20:35:35 UTC ---
Fixed for 4.6.  I'm somewhat reluctant to apply the patch to earlier releases,
since G++ was following the letter of the standard already, but am willing to
reconsider if someone really wants it in an earlier release.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2011-03-05 20:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-28 23:10 [Bug c++/46220] New: Error: invalid covariant return type generated for incomplete class type nathan.keynes at oracle dot com
2010-10-28 23:16 ` [Bug c++/46220] [4.3/4.4/4.5/4.6 Regression] Error: invalid covariant return type generated for incomplete class type and different qualifer pinskia at gcc dot gnu.org
2010-10-29  0:45 ` redi at gcc dot gnu.org
2010-10-29  0:51 ` redi at gcc dot gnu.org
2010-10-29  1:16 ` redi at gcc dot gnu.org
2010-11-12 14:51 ` rguenth at gcc dot gnu.org
2011-03-03 20:52 ` jason at gcc dot gnu.org
2011-03-04 15:18 ` jason at gcc dot gnu.org
2011-03-05 20:35 ` jason at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).