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

            Bug ID: 77264
           Summary: [7 Regression] std::string's replace gives wrong
                    results with C++17, works with C++11
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
  Target Milestone: ---

Running
  g++ -std=c++11 test.cc && ./a.out > working
  g++ -std=c++17 test.cc && ./a.out > failing
  diff -U0 working failing
shows:
  --- working     2016-08-16 12:50:40.318596035 +0200
  +++ failing     2016-08-16 12:50:40.870592038 +0200
  @@ -1 +1 @@
  -RESULT: Running <This_Program>
  +RESULT: Running <>

Namely, the replace call does not work with --std=c++17, but only with
--std++11. I think it worked two weeks ago. It definitely worked a month ago.


// ----------- test.cc ----------------
#include <string>

std::string&
string_replace (std::string& str, const std::string& old_str,
                const std::string& new_str)
{
  size_t pos = 0;

  while ((pos = str.find(old_str, pos)) != std::string::npos)
    {
      str.replace (pos, old_str.length (), new_str);
      pos += new_str.length ();
    }

  return str;
}

int main () {
  std::string str("Running <PROGRAM_NAME>");
  std::string old_str("PROGRAM_NAME");
  std::string new_str("This_Program");

  __builtin_printf ("RESULT: %s\n",
                    string_replace(str, old_str, new_str).c_str());
  return 0;
}

Reply via email to