[LLVMbugs] [Bug 19916] New: Extra temporaries with conditional expression and implicit conversion of class type to xvalue via UDC

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Jun 1 19:32:06 PDT 2014


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

            Bug ID: 19916
           Summary: Extra temporaries with conditional expression and
                    implicit conversion of class type to xvalue via UDC
           Product: clang
           Version: 3.4
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: hstong at ca.ibm.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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

-- 
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/20140602/90fdcd22/attachment.html>


More information about the llvm-bugs mailing list