<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><span class="vcard"><a class="email" href="mailto:richard-llvm@metafoo.co.uk" title="Richard Smith <richard-llvm@metafoo.co.uk>"> <span class="fn">Richard Smith</span></a>
</span> changed
<a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED INVALID - Segmentation fault involving std::initializer_list <std::pair <std::string, int>>"
href="http://llvm.org/bugs/show_bug.cgi?id=20407">bug 20407</a>
<br>
<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>What</th>
<th>Removed</th>
<th>Added</th>
</tr>
<tr>
<td style="text-align:right;">Status</td>
<td>NEW
</td>
<td>RESOLVED
</td>
</tr>
<tr>
<td style="text-align:right;">Resolution</td>
<td>---
</td>
<td>INVALID
</td>
</tr></table>
<p>
<div>
<b><a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED INVALID - Segmentation fault involving std::initializer_list <std::pair <std::string, int>>"
href="http://llvm.org/bugs/show_bug.cgi?id=20407#c6">Comment # 6</a>
on <a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED INVALID - Segmentation fault involving std::initializer_list <std::pair <std::string, int>>"
href="http://llvm.org/bugs/show_bug.cgi?id=20407">bug 20407</a>
from <span class="vcard"><a class="email" href="mailto:richard-llvm@metafoo.co.uk" title="Richard Smith <richard-llvm@metafoo.co.uk>"> <span class="fn">Richard Smith</span></a>
</span></b>
<pre>Oh, I see. Yes, I can reproduce the crash; it's a bug in your code. This:
std::initializer_list<std::pair<std::string, int>> values({{"0", 0}, {"1",
1}, {"2", 2}});
... creates a temporary std::initializer_list object (the {...}), then passes
it as an argument to the constructor of 'values'. The underlying array is not
lifetime-extended, so you're referring to an element of the array after it's
destroyed.
Deleting the parens results in the array being lifetime-extended, so it works.
Think of it like this:
struct init_list {
std::pair<std::string, int> (&&values)[2];
};
init_list values(init_list{{{"0", 0}, {"1", 1}, {"2", 2}}}); // does not
lifetime-extend array temporary
init_list values{{{"0", 0}, {"1", 1}, {"2", 2}}}; // lifetime-extends array
temporary</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>