<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 --- - Temporary expression result of dynamic_cast not lifetime-extended but corresponding static_cast is"
href="http://llvm.org/bugs/show_bug.cgi?id=20227">20227</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Temporary expression result of dynamic_cast not lifetime-extended but corresponding static_cast is
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</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>Under the wording from
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3918.html">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3918.html</a>
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:
<span class="quote">> cat tempExprDynamicCast.cc </span >
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:
<span class="quote">> clang++ -std=c++1y -Wall -Wextra -Wno-unused-variable -pedantic-errors tempExprDynamicCast.cc && ./a.out </span >
~A()
Hello from main().
Return: 0x00:0
### EXPECTED OUTPUT:
Hello from main().
~A()
### COMPILER VERSION INFO:
<span class="quote">> clang++ -v</span >
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</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>