[libcxx-commits] [PATCH] D155276: [libc++] Implement ostringstream members of P0408R7 (Efficient Access to basic_stringbuf's Buffer)

Leonard Chan via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jul 31 13:23:40 PDT 2023


leonardchan added a comment.

It looks like this change causes an out of range exception to be thrown for this snippet:

  // ./bin/clang++ -std=c++20 /tmp/test.cc -g
  #include <iostream>
  #include <sstream>
  
  int main() {
    std::ostringstream oss;
    std::cerr << std::move(oss).str();
    return 0;
  }

This fails with `libc++abi: terminating due to uncaught exception of type std::out_of_range: basic_string` but doesn't prior to this patch. It looks like the failure comes from this bit here:

      _LIBCPP_HIDE_FROM_ABI_SSTREAM string_type str() && {
          const basic_string_view<_CharT, _Traits> __view = view();
          string_type __result(std::move(__str_), __view.data() - __str_.data(), __view.size());
          __str_.clear();
          __init_buf_ptrs();
          return __result;
      }

Where `__view.data() - __str_.data()` is an absurdly large value for the `pos` argument in the string ctor:

  #11 0x00005555555a960d in std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char> >::basic_string (this=0x7fffffffd5f8, __str=..., __pos=18446603336221206952, __n=0, __a=...)

Perhaps the `pos` is actually a negative number or `view.data()` is actually `nullptr`? Would you be able to send out a fix or revert? Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155276



More information about the libcxx-commits mailing list