[libcxx-commits] [PATCH] D156783: [libc++] Fix `std::out_of_range` thrown from `basic_stringbuf::str() &&`

Piotr Fusik via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Aug 1 09:02:50 PDT 2023


pfusik marked an inline comment as done.
pfusik added inline comments.


================
Comment at: libcxx/include/sstream:405
+        if (!__view.empty())
+            __result.assign(std::move(__str_), __view.data() - __str_.data(), __view.size());
         __str_.clear();
----------------
Mordante wrote:
> Depending on the order of evaluation `__view.data() - __str_.data()` may be used after `__str_` has been moved. Lets determine the size before `assign`. This is pre-existing.
> 
> Whether this is save depends on the order in which the function arguments are evaluated. Clang and GCC use a different order.
I was also having this concern for a moment. :) But `std::move` is just a cast that does not modify its argument. The actual move is inside `assign`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156783/new/

https://reviews.llvm.org/D156783



More information about the libcxx-commits mailing list