https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101458

            Bug ID: 101458
           Summary: An invalid covaraint return type is accepted
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xmh970252187 at gmail dot com
  Target Milestone: ---

struct L{};
struct M:L{};
L l;
M m;
struct A{
    virtual L&& fun(){
        return std::move(l);
    }
};
struct B:A{
    M&  fun(){
        return m;
    }
};

In terms of [class.virtual#7.1]
> The return type of an overriding function shall be either identical to the 
> return type of the overridden function or covariant with the classes of the 
> functions. If a function D​::​f overrides a function B​::​f, the return types 
> of the functions are covariant if they satisfy the following criteria:  
>> both are pointers to classes, both are lvalue references to classes, or both 
>> are rvalue references to classes

It is obvious that the return type of `A::fun` is an rvalue reference while
that of `B::fun` is an lvalue reference. The overriding function defined in `B`
has an invalid covariant type, whereas GCC accept the code.
  • [Bug c++/101458] New: An invali... xmh970252187 at gmail dot com via Gcc-bugs

Reply via email to