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

            Bug ID: 89117
           Summary: [9 regression] filesystem::path's replace_extension()
                    broken?
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: h2+bugs at fsfe dot org
  Target Milestone: ---

In GCC9 a call to replace_extension() no longer removes the extension from a
filesystem::path. This leads to very unexpected behaviour without prior warning
or error.

Example:

#include <iostream>
#include <filesystem>

int main()
{
    std::filesystem::path p{"/tmp/abc.txt.gz"};
    std::cout << p << '\t' << p.extension() << '\n';
    p.replace_extension(); // remove .gz
    std::cout << p << '\t' << p.extension() << '\n';
}

hannes@fbsdmain /tmp % g++8 -std=c++17  test.cpp -lstdc++fs
hannes@fbsdmain /tmp % ./a.out
"/tmp/abc.txt.gz"   ".gz"
"/tmp/abc.txt"      ".txt"
hannes@fbsdmain /tmp % g++9 -std=c++17  test.cpp -lstdc++fs
hannes@fbsdmain /tmp % ./a.out
"/tmp/abc.txt.gz"   ".gz"
"/tmp/abc.txt"      ".gz"


These are my tested versions:
g++8 (FreeBSD Ports Collection) 8.2.1 20190118
g++9 (FreeBSD Ports Collection) 9.0.0 20190113 (experimental)

Reply via email to