https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86169

            Bug ID: 86169
           Summary: .data() fails to unshare strings
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mpolacek at gcc dot gnu.org
  Target Milestone: ---

#include <string>

int main()
{
  const std::string s0{"hello world"};
  std::string s1 {s0};
  std::string s2 {s0};

  char* p = s1.data();
  *p = ' ';

  if (s0.compare ("hello world") != 0)
    __builtin_abort ();
  if (s2.compare ("hello world") != 0)
    __builtin_abort ();

  return 0;
}

$ g++ a.cpp -std=c++17 -D_GLIBCXX_USE_CXX11_ABI=1; ./a.out
$ g++ a.cpp -std=c++17 -D_GLIBCXX_USE_CXX11_ABI=0; ./a.out
Aborted (core dumped)

Reply via email to