Bug 84159

Summary: filesystem::path::operator/= with has root directory path
Product: gcc Reporter: Akira Takahashi <faithandbrave>
Component: libstdc++Assignee: Jonathan Wakely <redi>
Status: RESOLVED FIXED    
Severity: normal CC: daniel.kruegler, webrown.cpp
Priority: P3    
Version: 8.0   
Target Milestone: 8.2   
Host: Target:
Build: Known to work:
Known to fail: 8.1.0 Last reconfirmed: 2018-05-14 00:00:00

Description Akira Takahashi 2018-02-01 06:58:20 UTC
Standard says: 

N4660 30.10.8.4.3 path appends [fs.path.append]

// On POSIX,
path("foo") / ""; // yields "foo/"
path("foo") / "/bar"; // yields "/bar"

However, 2nd line yields "foo/bar".

#include <iostream>
#include <filesystem>

namespace fs = std::filesystem;

int main()
{
  fs::path p = "foo";
  p /= "/bar";
  std::cout << << p << std::endl;
}
Comment 1 Jonathan Wakely 2018-05-14 22:59:07 UTC
Looks like I changed path::operator/=(const path&) to conform to the C++17 semantics, but not the other overload of path::operator/= that takes strings, nor the overloads of path::append.
Comment 2 Jonathan Wakely 2018-05-15 12:07:41 UTC
Author: redi
Date: Tue May 15 12:07:09 2018
New Revision: 260255

URL: https://gcc.gnu.org/viewcvs?rev=260255&root=gcc&view=rev
Log:
PR libstdc++/84159 fix appending strings to paths

The path::operator/=(const Source&) and path::append overloads were
still following the semantics of the Filesystem TS not C++17. Only
the path::operator/=(const path&) overload was correct.

This change adds more tests for path::operator/=(const path&) and adds
new tests to verify that the other append operations have equivalent
behaviour.

	PR libstdc++/84159
	* include/bits/fs_path.h (path::operator/=, path::append): Construct
	temporary path before calling _M_append.
	(path::_M_append): Change parameter to path and implement C++17
	semantics.
	* testsuite/27_io/filesystem/path/append/path.cc: Add helper function
	and more examples from the standard.
	* testsuite/27_io/filesystem/path/append/source.cc: New.
	* testsuite/27_io/filesystem/path/decompose/filename.cc: Add comment.
	* testsuite/27_io/filesystem/path/nonmember/append.cc: New.

Added:
    trunk/libstdc++-v3/testsuite/27_io/filesystem/path/append/source.cc
    trunk/libstdc++-v3/testsuite/27_io/filesystem/path/nonmember/append.cc
      - copied, changed from r260254, trunk/libstdc++-v3/testsuite/27_io/filesystem/path/append/path.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/bits/fs_path.h
    trunk/libstdc++-v3/testsuite/27_io/filesystem/path/append/path.cc
    trunk/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/filename.cc
Comment 3 Jonathan Wakely 2018-05-15 12:57:57 UTC
Author: redi
Date: Tue May 15 12:57:25 2018
New Revision: 260257

URL: https://gcc.gnu.org/viewcvs?rev=260257&root=gcc&view=rev
Log:
PR libstdc++/84159 fix appending strings to paths

The path::operator/=(const Source&) and path::append overloads were
still following the semantics of the Filesystem TS not C++17. Only
the path::operator/=(const path&) overload was correct.

This change adds more tests for path::operator/=(const path&) and adds
new tests to verify that the other append operations have equivalent
behaviour.

	PR libstdc++/84159
	* include/bits/fs_path.h (path::operator/=, path::append): Construct
	temporary path before calling _M_append.
	(path::_M_append): Change parameter to path and implement C++17
	semantics.
	* testsuite/27_io/filesystem/path/append/path.cc: Add helper function
	and more examples from the standard.
	* testsuite/27_io/filesystem/path/append/source.cc: New.
	* testsuite/27_io/filesystem/path/decompose/filename.cc: Add comment.
	* testsuite/27_io/filesystem/path/nonmember/append.cc: New.

Added:
    branches/gcc-8-branch/libstdc++-v3/testsuite/27_io/filesystem/path/append/source.cc
    branches/gcc-8-branch/libstdc++-v3/testsuite/27_io/filesystem/path/nonmember/append.cc
      - copied, changed from r260247, branches/gcc-8-branch/libstdc++-v3/testsuite/27_io/filesystem/path/append/path.cc
Modified:
    branches/gcc-8-branch/libstdc++-v3/ChangeLog
    branches/gcc-8-branch/libstdc++-v3/include/bits/fs_path.h
    branches/gcc-8-branch/libstdc++-v3/testsuite/27_io/filesystem/path/append/path.cc
    branches/gcc-8-branch/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/filename.cc
Comment 4 Jonathan Wakely 2018-05-15 13:53:11 UTC
Fixed for 8.2, thanks for the report.