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

            Bug ID: 69436
           Summary: Method returning "auto&" fails to resolve "*this"
                    (-sdt=c++17)
           Product: gcc
           Version: 5.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vmorgulys at gmail dot com
  Target Milestone: ---

Hello everybody,

Here is a test case.

    //bad auto

    class c1
    {
     public:

     auto& f1()
     {
      return *this;
     }

     auto& f2(auto v)
     {
      return *this;
     }
    };

    int main(int count,const char** arguments)
    {
     c1 a;

     a.f1(); //ok
     a.f2(42); //failed

     return 0;
    }

Compiled with:

    g++ -O3 -g -std=c++17 -fmax-errors=8 -Wall -Wno-strict-overflow

The error message is:

    source/main.cpp: In instantiation of ‘auto& c1::f2(auto:1) [with auto:1 =
int]’:
    source/main.cpp:23:9:   required from here
    source/main.cpp:14:11: error: invalid initialization of reference of type
‘int&’ from expression of type ‘c1’
   return *this;

I'm not sure if it's a bug or not. It seems related to:

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

Let me know if I'm wrong.

Cheers.

Reply via email to