[llvm-bugs] [Bug 25098] 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 13:09:58 PDT 2015


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

Richard Smith <richard-llvm at metafoo.co.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |richard-llvm at metafoo.co.uk
         Resolution|---                         |INVALID

--- Comment #1 from Richard Smith <richard-llvm at metafoo.co.uk> ---
The outcome here comes down to the (unspecified) order of evaluation. In:

  uut["1"] = boost::make_shared<ThrowsInConstructor>(1);

GCC evaluates the right-hand side first, and so throws before calling
operator[] (leaving the map empty). Clang evaluates the left-hand side first,
and so throws after calling operator[] (leaving the map with a single element).

If you change the code to:

  auto &elem = uut["1"];
  elem = boost::make_shared<ThrowsInConstructor>(1);

or:

  auto &&val = boost::make_shared<ThrowsInConstructor>(1);
  uut["1"] = std::move(val);

... you'll get the same result from both compilers (map size 1 in the first
case, map size 0 in the second).

-- 
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/13746556/attachment.html>


More information about the llvm-bugs mailing list