<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/55328>55328</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            std::to_string() crashes with _LIBCPP_DEBUG == 1
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            libc++,
            crash
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          llunak
      </td>
    </tr>
</table>

<pre>
    Steps to reproduce:

$ cat a.cpp
#define _LIBCPP_DEBUG 1
#include <string>

int main()
{
    int i = 20;
    std::string s = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + std::to_string(i) + "b";
    return 0;
}

$ clang++ -stdlib=libc++ a.cpp -g
$ gdb a.out
(gdb) run
Program received signal SIGSEGV, Segmentation fault.
(gdb) backtrace
#0  0x00007ffff7f1f1ca in std::__1::__libcpp_db::swap (this=0x7ffff7ff27a0 <std::__1::__get_db()::db>, c1=0x7fffffffda88, c2=0x7fffffffda70) at /home/seli/build/src/llvm/libcxx/src/debug.cpp:442
#1  0x0000000000401a22 in std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string (this=0x7fffffffda88, __str=...) at /usr/include/c++/v1/string:1983
#2  0x0000000000401624 in std::__1::operator+<char, std::__1::char_traits<char>, std::__1::allocator<char> > (__lhs=0x403124 'x' <repeats 40 times>, __rhs=...) at /usr/include/c++/v1/string:4273
#3  0x0000000000401508 in main () at a.cpp:7

The problem exists because std::to_string() calls std::string ctor from libc++'s string.cpp, which has not been compiled with _LIBCPP_DEBUG == 1, so __debug_db_insert_c() is a no-op.
(gdb) bt
#0  std::__1::__debug_db_insert_c<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > (__c=0x7fffffffda70) at include/c++/v1/__debug:217
#1  0x00007ffff7f18aa3 in std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string<char*, void> (this=0x7fffffffda70, __first=0x7fffffffd9ed "20", __last=0x7fffffffd9ef "") at include/c++/v1/string:2303
#2  0x00007ffff7f1542e in std::__1::(anonymous namespace)::i_to_string<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int> (v=20) at /home/seli/build/src/llvm/libcxx/src/string.cpp:483
#3  0x00007ffff7f153d1 in std::__1::to_string (val=20) at /home/seli/build/src/llvm/libcxx/src/string.cpp:488
#4  0x00000000004014f6 in main () at d.cpp:7

This is presumably a similar problem like #53669.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzNVluPszYQ_TXkxdoIDAnkIQ_ZS1af1IeVtu0rMmCCuwYj2-zl3_eYQMi3sG3Vu5UEYg_jM8czZ8hU8bF_trw1xCqieatV0eXcCw-ef-_54y-NSM4sYeu8bcepsOClaDhJf_h2e_f0lN4_3P70SILLsmhy2RWceOGdsVo0Jy98uHYqGktqJhqPJh7dDSvx7fmGYDgDgcfvCfW98GrB2MIBDA9nv8T0Rh6l739wwBTmt5Mjq9IBI00E0PSrsMrw_W5rzW2nGzLh8eL7GVOSOUe3zscNtpAiAz785sNkTyO5OU2PnIoMs6qz41SCGYdDd8156kmrk2Y1AORcvPKCGHFqmCTP3x6fHx5_9ugdeeanmjeWWaEaUrJO2vVndxnLX6xmOODxlHxC_HcfIy4x4jIog5yB-ombNA3GGxdD26bwdab_jbVgKbGVMIjQfx98lDRm_vnc5z5O3DoH50Pv55y7BxdAHkxeMAqWJP00_TQd-y4W5KNHj5WqOS6GS5zbMeuELNxfDa6PUr7W7gLU7syH2YJn3alP5PAQRfTCRDAycR6RHzCkySITGTMiHzMmvMsrph3QuaFbSUG4sGa0O4c6N2VSKtSY0pMhccazDeeMX3GVOiOsrNfriaPOAN5xqEfcDXmIu9fA0TLEcQh2SXihg87o2CJRF-lQLdc9cvj8Z9lwsSMNq3PwkR8GwOTRGKcbu4SDgHFmDYl8YkXNzeA_T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