[cfe-dev] [bug] Wrong overload chosen when a conversion operator to const T() exists

Philipp Moeller philipp.moeller at geometryfactory.com
Mon Oct 8 05:54:17 PDT 2012


Hello,

the following snippet does compile on gcc 4.7.1, but fails with clang
trunk r165389

struct Y {};

struct X {
  operator const Y() const { return Y(); }
};

void f(Y&& y) {}

int main()
{
  f(X());
  return 0;
}

As far as I can tell, clang is right to reject this code as it would
require two user-defined conversion.

However, when another overload void f(const Y& y); is added clang still
wont accept the code. This problem also appears when using standard
library containers (vector::push_back).

Shouldn't clang choose the f(const Y&) over f(Y&&) and accept the code?

AFAIK, this behavior is reproducible on the current Apple clang 4.1 as
well.

Cheers,
Philipp Moeller 
GeometryFactory



More information about the cfe-dev mailing list