<html>
<head>
<base href="https://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 --- - Missing destructors for default arguments created during list-initialization of array"
href="https://llvm.org/bugs/show_bug.cgi?id=22877">22877</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Missing destructors for default arguments created during list-initialization of array
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</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>zilla@kayari.org
</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>From
<a href="http://stackoverflow.com/questions/28991043/why-does-clang-destroy-only-one-foo-object">http://stackoverflow.com/questions/28991043/why-does-clang-destroy-only-one-foo-object</a>
extern "C" int puts(const char*);
struct foo {
int* n;
foo() : n(new int) { puts("cons"); }
~foo() { puts("dest"); delete n; }
foo(foo&& f) : n(f.n) { f.n = 0; }
};
struct bar {
bar(foo t=foo{}) { }
};
int main() {
bar b[3]{};
}
clang++ -std=c++11 leak.cc -fsanitize=address
The program prints
cons
cons
cons
dest
=================================================================
==11813==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 8 byte(s) in 2 object(s) allocated from:
#0 0x4eae5b in operator new(unsigned long)
/home/jwakely/src/llvm/llvm/projects/compiler-rt/lib/asan/asan_new_delete.cc:62:35
#1 0x4ec178 in foo::foo() /tmp/leak.cc:5:15
#2 0x4ebdfc in main /tmp/leak.cc:15:14
#3 0x3236e21d64 in __libc_start_main (/lib64/libc.so.6+0x3236e21d64)
SUMMARY: AddressSanitizer: 8 byte(s) leaked in 2 allocation(s).
The expected output is:
cons
dest
cons
dest
cons
dest
This is with:
clang version 3.7.0 (trunk 229722) (llvm/trunk 229719)
Target: x86_64-unknown-linux-gnu
Thread model: posix</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>