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

            Bug ID: 59296
           Summary: [c++11] ref-qualified member function is ambiguous
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eric.niebler at gmail dot com

The following code fails to compile:

struct S
{
    constexpr int foo() const & { return 0; }
    constexpr int foo() const && { return 42; }
};

int main()
{
    constexpr int i = S{}.foo();
}

The error I get is:

$ /usr/local/gcc-4.8.2/bin/g++ -std=gnu++11 -c test.cpp
test.cpp: In function ‘int main()’:
test.cpp:9:31: error: call of overloaded ‘foo()’ is ambiguous
     constexpr int i = S{}.foo();
                               ^
test.cpp:9:31: note: candidates are:
test.cpp:3:19: note: constexpr int S::foo() const &
     constexpr int foo() const & { return 0; }
                   ^
test.cpp:4:19: note: constexpr int S::foo() const &&
     constexpr int foo() const && { return 42; }
                   ^

The code in question is not ambiguous. The object is clearly an rvalue, so the
&&-qualified member should be preferred.

Reply via email to