<html>
<head>
<base href="https://bugs.llvm.org/">
</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 - Two type that are not reference-related can further converted in reference initialization"
href="https://bugs.llvm.org/show_bug.cgi?id=51763">51763</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Two type that are not reference-related can further converted in reference initialization
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++2a
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>xmh970252187@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>char cc;
struct A{
operator char&(){
return cc;
}
};
int main(){
A a;
int&& rf = a;
}
Clang rejects this example while GCC accepts it. GCC has a correct
interpretation for this example, since [dcl.init.ref#5.4.1] make `A::operator
char&()` be a candidate to convert the original initializer expression `a`,
which brings it to type `char`, as per [dcl.init.ref#5.4.1]
<span class="quote">> The result of the call to the conversion function, as described for the non-reference copy-initialization, is then used to direct-initialize the reference. For this direct-initialization, user-defined conversions are not considered. </span >
It means the effect would be the same as that `int&& rf(a.operator char&())`,
since their types are not reference-related, [dcl.init.ref#5.4.2] can apply to
it to do the further conversion, which converts the result of `a.operator
char&()` to type `T`, no user-defined conversion is applied, hence the whole
reference initialization would like to be that `int&&
rf(static_cast<int>(a.operator char&()))`.</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>