<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 --- - libc++ std::map::operator[] is different (worse) than libstdc++ with C++11, move semantics, and exception handling"
href="https://llvm.org/bugs/show_bug.cgi?id=25098">25098</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>libc++ std::map::operator[] is different (worse) than libstdc++ with C++11, move semantics, and exception handling
</td>
</tr>
<tr>
<th>Product</th>
<td>libc++
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</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>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>jim.king@simplivity.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=15023" name="attach_15023" title="source code demonstrating the issue">attachment 15023</a> <a href="attachment.cgi?id=15023&action=edit" title="source code demonstrating the issue">[details]</a></span>
source code demonstrating the issue
I recently came across a problem demonstrated by the attached code.
It appears that in C++11 with the introduction of std::map::operator[](T&&), it
is possible to end up with an entry in the map that has a default value rather
than the intended value. Exception safety in the standard is not clear with
respect to operator[], although it is for insert() and emplace(). When using
libstdc++ the result of this test program is that the map is not modified.
When using libc++ the result of this test is that a default (empty) smart
pointer is inserted into the map, which seems like a bug.
g++ in this case is 4.8.2 on Ubuntu 14.04 LTS.
clang++ in this case is "Last update : Tue, 06 Oct 2015 17:11:24 UTC /
Revision: 249410"
jking@dvm5:/tmp$ g++ libcxx-map-operator-at-move-exception-error.cpp -o
testmap-g++
jking@dvm5:/tmp$ ldd testmap-g++
linux-vdso.so.1 => (0x00007ffcf15ba000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6
(0x00007fca8eb63000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fca8e94d000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fca8e588000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fca8e282000)
/lib64/ld-linux-x86-64.so.2 (0x00007fca8ee67000)
jking@dvm5:/tmp$ clang++ libcxx-map-operator-at-move-exception-error.cpp
--stdlib=libc++ -lc++abi -o testmap-clang++
jking@dvm5:/tmp$ ldd testmap-clang++
linux-vdso.so.1 => (0x00007fff1e5e8000)
libc++abi.so.1 => /usr/local/lib/libc++abi.so.1 (0x00007fa6166d9000)
libc++.so.1 => /usr/local/lib/libc++.so.1 (0x00007fa616613000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fa616254000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fa61603e000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa615c79000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0
(0x00007fa615a5b000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fa615853000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa61655a000)
jking@dvm5:/tmp$ ./testmap-g++
caught = 1 (should be true)
map size = 0 (should be 0)
jking@dvm5:/tmp$ ./testmap-clang++
caught = 1 (should be true)
map size = 1 (should be 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>