<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Copy initialization using conversion operator does not find correct candidates for initialization of final result"
href="http://llvm.org/bugs/show_bug.cgi?id=16773">16773</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Copy initialization using conversion operator does not find correct candidates for initialization of final result
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.2
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>hstong@ca.ibm.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>I have a reduced test case.
MSVC seems to work fine (online compiler test: <a href="http://rise4fun.com/Vcpp/2sQ">http://rise4fun.com/Vcpp/2sQ</a>).
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</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>