2

The following code uses return type deduction (auto) and different methods for L-value and R-value objects. It seems when combining the two, gcc 4.9.2 has problems with overload resolution: "call of overloaded 'f()' is ambiguous".
Is this a bug or just another strange C++ corner case? Clang accepts it as expected.

struct T {
  auto f() & {
    return int{0};
  }
  auto f() && {
    return string{""};
  }
};

void test_it() {
  //Calling with L-value object. Fails with "call of overloaded 'f()' is ambiguous").
  T t;
  int s = t.f();

  //Calling with R-value object. Fails with "call of overloaded 'f()' is ambiguous").
  string i = T{}.f();
}

The example can be studied using online compilers here:
gcc 4.9.2: http://goo.gl/IE19y8
clang 3.5.1: http://goo.gl/FRbD8Z

1 Answers1

0

It turned out to be a known bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60943