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

            Bug ID: 20227
           Summary: Temporary expression result of dynamic_cast not
                    lifetime-extended but corresponding static_cast is
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]
    Classification: Unclassified

Under the wording from
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3918.html

a dynamic_cast like the one in the case below is a temporary expression and the
lifetime of the temporary is extended.

Note that using static_cast in place of dynamic_cast with Clang causes the
lifetime extension to occur.
The inconsistency is undesirable.

### SOURCE:
> cat tempExprDynamicCast.cc 
extern "C" int printf(const char *, ...);

struct A { ~A(); };

int main(void) {
   A &&a = dynamic_cast<A &&>(A());
   printf("Hello from main().\n");
}

A::~A() { printf("~A()\n"); }
Return:  0x00:0


### COMPILER INVOCATION AND OUTPUT:
> clang++ -std=c++1y -Wall -Wextra -Wno-unused-variable -pedantic-errors 
> tempExprDynamicCast.cc && ./a.out 
~A()
Hello from main().
Return:  0x00:0


### EXPECTED OUTPUT:
Hello from main().
~A()


### COMPILER VERSION INFO:
> clang++ -v
clang version 3.5.0 
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
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
Return:  0x00:0

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to