[llvm-bugs] [Bug 25098] New: libc++ std::map::operator[] is different (worse) than libstdc++ with C++11, move semantics, and exception handling

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Oct 7 10:02:21 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=25098

            Bug ID: 25098
           Summary: libc++ std::map::operator[] is different (worse) than
                    libstdc++ with C++11, move semantics, and exception
                    handling
           Product: libc++
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: jim.king at simplivity.com
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com
    Classification: Unclassified

Created attachment 15023
  --> https://llvm.org/bugs/attachment.cgi?id=15023&action=edit
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 at dvm5:/tmp$ g++ libcxx-map-operator-at-move-exception-error.cpp -o
testmap-g++
jking at 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 at dvm5:/tmp$ clang++ libcxx-map-operator-at-move-exception-error.cpp
--stdlib=libc++ -lc++abi -o testmap-clang++
jking at 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 at dvm5:/tmp$ ./testmap-g++
caught = 1 (should be true)
map size = 0 (should be 0)

jking at dvm5:/tmp$ ./testmap-clang++
caught = 1 (should be true)
map size = 1 (should be 0)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20151007/4a2b580a/attachment.html>


More information about the llvm-bugs mailing list