<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 --- - Extra temporaries with conditional expression and implicit conversion of class type to xvalue via UDC"
href="http://llvm.org/bugs/show_bug.cgi?id=19916">19916</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Extra temporaries with conditional expression and implicit conversion of class type to xvalue via UDC
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.4
</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++11
</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>The conditional operator as implemented by Clang introduces extra temporaries
when given a class that can be implicitly converted to an xvalue of the "other
type" through a conversion function.
N3290 subclause 5.16 [expr.cond] paragraph 3 applies. Note that the third
bullet contains an instance of "rvalue" which was replaced with "prvalue" as an
editorial fix.
The source below demonstrates that implicit conversion to int && from the
expression "aObj" is possible.
The conditions for the second bullet of [expr.cond]/3 is met.
The conversion in the other direction is not possible.
The end result from the last sentence of [expr.cond]/3 is that both the second
and third operand should be considered xvalues of type int for [expr.cond]/4.
### SOURCE:> cat condExprUDCtoXval_Xval.cc
int glob;
struct A {
operator int &&() { return static_cast<int &&>(glob); }
} aObj;
int &&implicitconvcheck = aObj;
int &&condExprResult = false ? aObj : aObj.operator int &&();
extern "C" int printf(const char *, ...);
int main() {
printf("address of implicitconvcheck %s consistent with direct binding\n",
&implicitconvcheck == &glob ? "is" : "is NOT");
printf("address of condExprResult %s consistent with direct binding\n",
&condExprResult == &glob ? "is" : "is NOT");
return 0;
}
Return: 0x00:0
### COMPILER INVOCATION AND OUTPUT:> clang++ -std=c++11
condExprUDCtoXval_Xval.cc && ./a.out
address of implicitconvcheck is consistent with direct binding
address of condExprResult is NOT consistent with direct binding
Return: 0x00:0
### EXPECTED OUTPUT:> ./a.out
address of implicitconvcheck is consistent with direct binding
address of condExprResult is consistent with direct binding
Return: 0x00:0
### VERSION INFO:> clang++ -v
clang version 3.4 (tags/RELEASE_34/final)
Target: powerpc64-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib/gcc/ppc64-redhat-linux/4.4.4
Found candidate GCC installation: /usr/lib/gcc/ppc64-redhat-linux/4.4.6
Selected GCC installation: /usr/lib/gcc/ppc64-redhat-linux/4.4.6
Return: 0x00:0</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>