调用重载限定符成员函数的重载是不明确的

Ori*_*ent 7 c++ overload-resolution c++11 ref-qualifier

当用G ++(gcc 4.8.1和MinGW 4.8.2 with -std=gnu++1yflag)编译我的代码时,我发现了一个奇怪的行为.在SSCCE的精神中,我隔离了以下代码段:

struct C
{

    template< typename X >
    auto
    f(X &&) const &
    { ; }

    template< typename X >
    auto
    f(X &&) &
    { ; }

    template< typename X >
    auto
    f(X &&) &&
    { ; }

};

int main()
{
    int i{};
#if 1
    C{}.f(i);
#endif
#if 1
    C c{};
    c.f(i);
#endif
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

它给出了一个错误:

main.cpp: In function 'int main()':
main.cpp:29:10: error: call of overloaded 'f(int&)' is ambiguous
     c.f(i);
          ^
main.cpp:29:10: note: candidates are:
main.cpp:6:5: note: auto C::f(X&&) const & [with X = int&]
     f(X &&) const &
     ^
main.cpp:11:5: note: auto C::f(X&&) & [with X = int&]
     f(X &&) &
     ^
main.cpp:16:5: note: auto C::f(X&&) && [with X = int&]
     f(X &&) &&
     ^
Run Code Online (Sandbox Code Playgroud)

但在情况下#if 1#if 0,或#if 0#if 1会正常编译.此外,如果我用auto's 替换所有' voids,那么所有编译也成功.

是错误,还是我的误导?

Cas*_*sey 4

g++ 4.8.2 也有同样的问题,但更简单(Live at coliru):

struct A {
    auto f() & {}
    auto f() && {}
};

int main() {
    A{}.f();
    A a;
    a.f();
}
Run Code Online (Sandbox Code Playgroud)

尽管该程序显然是正确的。这似乎是引用限定符和返回类型推导之间的交互中的一个错误:大概推导过程是从隐式对象参数中剥离限定符,然后再将它们交给重载解析。

我已将此报告为GCC bug 60943