[LLVMbugs] [Bug 16773] New: Copy initialization using conversion operator does not find correct candidates for initialization of final result

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Aug 1 22:11:04 PDT 2013


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: unassignedclangbugs at nondot.org
          Reporter: hstong at ca.ibm.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130802/9939b2ee/attachment.html>


More information about the llvm-bugs mailing list