[Bug libstdc++/94063] filesystem::path concatenation doesn't work for Windows root-paths

2020-03-12 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94063

--- Comment #6 from Martin Liška  ---
commit r9-8369-g7ef07b622d8c2fca35813bf50669dcd663fe5cf2
Author: Jonathan Wakely 
Date:   Thu Mar 12 17:39:05 2020 +

libstdc++: Handle type-changing path concatenations (PR 94063)

The filesystem::path::operator+= and filesystem::path::concat functions
operate directly on the native format of the path and so can cause a
path to mutate to a completely different type.

For Windows combining a filename "x" with a filename ":" produces a
root-name "x:". Similarly, a Cygwin root-directory "/" combined with a
root-directory and filename "/x" produces a root-name "//x".

Before this patch the implemenation didn't support those kind of
mutations, assuming that concatenating two filenames would always
produce a filename and concatenating with a root-dir would still have a
root-dir.

This patch fixes it simply by checking for the problem cases and
creating a new path by re-parsing the result of the string
concatenation. This is slightly suboptimal because the argument has
already been parsed if it's a path, but more importantly it doesn't
reuse any excess capacity that the path object being modified might
already have allocated.

Backport from mainline
2020-03-09  Jonathan Wakely  

PR libstdc++/94063
* src/c++17/fs_path.cc (path::operator+=(const path&)): Add kluge
to
handle concatenations that change the type of the first component.
(path::operator+=(basic_string_view)): Likewise.
* testsuite/27_io/filesystem/path/concat/94063.cc: New test.

[Bug libstdc++/94063] filesystem::path concatenation doesn't work for Windows root-paths

2020-03-12 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94063

Jonathan Wakely  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #5 from Jonathan Wakely  ---
Fixed for 9.4

[Bug libstdc++/94063] filesystem::path concatenation doesn't work for Windows root-paths

2020-03-11 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94063

Martin Liška  changed:

   What|Removed |Added

 CC||marxin at gcc dot gnu.org

--- Comment #4 from Martin Liška  ---
commit r10-7095-gea182fe63634bb5b7913b3f1b6846e1900c5e0c4
Author: Jonathan Wakely 
Date:   Mon Mar 9 23:22:57 2020 +

libstdc++: Handle type-changing path concatenations (PR 94063)

The filesystem::path::operator+= and filesystem::path::concat functions
operate directly on the native format of the path and so can cause a
path to mutate to a completely different type.

For Windows combining a filename "x" with a filename ":" produces a
root-name "x:". Similarly, a Cygwin root-directory "/" combined with a
root-directory and filename "/x" produces a root-name "//x".

Before this patch the implemenation didn't support those kind of
mutations, assuming that concatenating two filenames would always
produce a filename and concatenating with a root-dir would still have a
root-dir.

This patch fixes it simply by checking for the problem cases and
creating a new path by re-parsing the result of the string
concatenation. This is slightly suboptimal because the argument has
already been parsed if it's a path, but more importantly it doesn't
reuse any excess capacity that the path object being modified might
already have allocated. That can be fixed later though.

PR libstdc++/94063
* src/c++17/fs_path.cc (path::operator+=(const path&)): Add kluge
to
handle concatenations that change the type of the first component.
(path::operator+=(basic_string_view)): Likewise.
* testsuite/27_io/filesystem/path/concat/94063.cc: New test.

[Bug libstdc++/94063] filesystem::path concatenation doesn't work for Windows root-paths

2020-03-10 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94063

Jonathan Wakely  changed:

   What|Removed |Added

   Target Milestone|--- |9.4
 Status|NEW |ASSIGNED

--- Comment #3 from Jonathan Wakely  ---
Fixed for master with r10-7095-gea182fe63634bb5b7913b3f1b6846e1900c5e0c4

libstdc++: Handle type-changing path concatenations (PR 94063)

The filesystem::path::operator+= and filesystem::path::concat functions
operate directly on the native format of the path and so can cause a
path to mutate to a completely different type.

For Windows combining a filename "x" with a filename ":" produces a
root-name "x:". Similarly, a Cygwin root-directory "/" combined with a
root-directory and filename "/x" produces a root-name "//x".

Before this patch the implemenation didn't support those kind of
mutations, assuming that concatenating two filenames would always
produce a filename and concatenating with a root-dir would still have a
root-dir.

This patch fixes it simply by checking for the problem cases and
creating a new path by re-parsing the result of the string
concatenation. This is slightly suboptimal because the argument has
already been parsed if it's a path, but more importantly it doesn't
reuse any excess capacity that the path object being modified might
already have allocated. That can be fixed later though.

PR libstdc++/94063
* src/c++17/fs_path.cc (path::operator+=(const path&)): Add kluge
to
handle concatenations that change the type of the first component.
(path::operator+=(basic_string_view)): Likewise.
* testsuite/27_io/filesystem/path/concat/94063.cc: New test.


I plan to fix this for gcc 9.4 later. A more efficient fix would also be
possible.

[Bug libstdc++/94063] filesystem::path concatenation doesn't work for Windows root-paths

2020-03-09 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94063

--- Comment #2 from Jonathan Wakely  ---
The test case for Cygwin (which is expected to fail on other targets) is 

#include 
#include 

using std::filesystem::path;

int main()
{
  path p;

  p = "/";
  p += path("/x");
  assert( p.has_root_name() );
  assert( p.root_name() == p );

  p = "/";
  p += "/x";
  assert( p.has_root_name() );
  assert( p.root_name() == p );

  p = "/";
  p += path("/");
  assert( !p.has_root_name() );
  assert( p.has_root_directory() );

  p = "/";
  p += "/";
  assert( !p.has_root_name() );
  assert( p.has_root_directory() );
}

[Bug libstdc++/94063] filesystem::path concatenation doesn't work for Windows root-paths

2020-03-06 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94063

--- Comment #2 from Jonathan Wakely  ---
Oops, the testcase is missing "using std::filesystem::path;"

There's a similar problem for Cygwin with path("/") += "/"

[Bug libstdc++/94063] filesystem::path concatenation doesn't work for Windows root-paths

2020-03-06 Thread cvs-commit at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94063

--- Comment #1 from CVS Commits  ---
The master branch has been updated by Jonathan Wakely :

https://gcc.gnu.org/g:180eeeaeb200a07f7f24e1f203cd026880ff861c

commit r10-7062-g180eeeaeb200a07f7f24e1f203cd026880ff861c
Author: Jonathan Wakely 
Date:   Fri Mar 6 11:27:34 2020 +

libstdc++: Fix failing filesystem::path tests (PR 93244)

The checks for PR 93244 don't actually pass on Windows (which is the
target where the bug is present) because of a different bug, PR 94063.

This adjusts the tests to not be affected by 94063 so that they verify
that 93244 was fixed.

PR libstdc++/93244
* testsuite/27_io/filesystem/path/generic/generic_string.cc: Adjust
test to not fail due to PR 94063.
* testsuite/27_io/filesystem/path/generic/utf.cc: Likewise.
* testsuite/27_io/filesystem/path/generic/wchar_t.cc: Likewise.

[Bug libstdc++/94063] filesystem::path concatenation doesn't work for Windows root-paths

2020-03-05 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94063

Jonathan Wakely  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2020-03-05
 Ever confirmed|0   |1
  Known to fail||10.0, 9.2.0