<html>
<head>
<base href="https://bugs.llvm.org/">
</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 - init-capture of initializer_list fails to extend lifetime"
href="https://bugs.llvm.org/show_bug.cgi?id=39336">39336</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>init-capture of initializer_list fails to extend lifetime
</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>Keywords</th>
<td>miscompilation
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++14
</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>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Similar to PR 24164, but expressed using an initializer_list captured by value.
Clang does not extend the lifetime of the temporary array to the lifetime of
the init-capture. GCC does extend the lifetime.
### SOURCE (<stdin>):
#include <initializer_list>
extern "C" int printf(const char *, ...);
struct A {
A() = default;
A(const A &) = default;
~A() { printf("%s\n", __PRETTY_FUNCTION__); }
};
int main(void) {
A a;
[list = { a }] { printf("Hi.\n"); }();
}
### COMPILER INVOCATION:
clang++ -xc++ -std=c++14 -o prog -
### RUN INVOCATION:
./prog
### ACTUAL RUN OUTPUT:
A::~A()
Hi.
A::~A()
### EXPECTED RUN OUTPUT:
A::~A()
A::~A()
Hi.
### COMPILER VERSION INFO (clang++ -v):
clang version 8.0.0 (<a href="https://github.com/llvm-mirror/clang.git">https://github.com/llvm-mirror/clang.git</a>
bcda707b20ee8c1ad0ce4e9503c761c85e6ce624)
(<a href="https://github.com/llvm-mirror/llvm.git">https://github.com/llvm-mirror/llvm.git</a>
4998e62d5745cca132cf92cec718be0746e70bcf)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/wandbox/clang-head/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.0.0
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.0
Candidate multilib: .;@m64
Selected multilib: .;@m64</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>