[LLVMbugs] [Bug 20227] New: Temporary expression result of dynamic_cast not lifetime-extended but corresponding static_cast is
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Mon Jul 7 08:12:48 PDT 2014
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: unassignedclangbugs at nondot.org
Reporter: hstong at ca.ibm.com
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140707/b7992512/attachment.html>
More information about the llvm-bugs
mailing list