http://llvm.org/bugs/show_bug.cgi?id=16773

            Bug ID: 16773
           Summary: Copy initialization using conversion operator does not
                    find correct candidates for initialization of final
                    result
           Product: clang
           Version: 3.2
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]
    Classification: Unclassified

I have a reduced test case.
MSVC seems to work fine (online compiler test: http://rise4fun.com/Vcpp/2sQ).

The copy initialization of an object of type A from a class object of type
C is expected to find C::operator B &() as the function selected by overload
resolution.

The result of the call, an lvalue of type B, is then used to direct-initialize
the object that is the destination of the copy-initialization.
See C++11 subclause 8.5 [dcl.init] paragraph 16.

Note that the result of the call is specified to be used, not the result of the
user-defined conversion sequence which was considered for overload resolution.

The direct initialization from the lvalue of type B has for its candidates all
of the constructors for A (13.3.1.3 [over.match.ctor]).

Note that A(B &) has a standard conversion sequence from the lvalue of type B
to
its sole argument (the identity conversion).

clang++ seems to be fixated with the copy constructors for A instead of using
overload resolution for the direct initialization.

## Self-contained test case (main.cpp):
struct B;
struct A {
   A();
   A(const A &, bool = 0);
   A(const A &, short = 0);
   A(B &);
};

struct B : A { };

struct C {
   operator B &();
};

int main() {
   C c;
   A a = c;
}

## Compiler invocation:
clang++ '-std=c++11' -c main.cpp

## Compiler output:
main.cpp:17:6: error: ambiguous constructor call when copying variable of type
'B'
   A a = c;
     ^   ~
main.cpp:4:4: note: candidate constructor
   A(const A &, bool = 0);
   ^
main.cpp:5:4: note: candidate constructor
   A(const A &, short = 0);
   ^
1 error generated.

## Expected behaviour:
Clean compile.

## clang++ -v:
clang version 3.2 (trunk 158227)
Target: i386-pc-cygwin
Thread model: posix

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to