libstdc++: Ensure root-dir converted to forward slash (PR93244)

PR libstdc++/93244
	* include/bits/fs_path.h (path::generic_string<C,A>)
	[_GLIBCXX_FILESYSTEM_IS_WINDOWS]: Convert root-dir to forward-slash.
	* testsuite/27_io/filesystem/path/generic/generic_string.cc: Check
	root-dir is converted to forward slash in generic pathname.
	* testsuite/27_io/filesystem/path/generic/utf.cc: New test.
	* testsuite/27_io/filesystem/path/generic/wchar_t.cc: New test.
This commit is contained in:
Jonathan Wakely 2020-01-13 10:02:39 +00:00
parent e4379a931d
commit fe7cc34fd5
5 changed files with 154 additions and 0 deletions

View File

@ -1,5 +1,13 @@
2020-01-13 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/93244
* include/bits/fs_path.h (path::generic_string<C,A>)
[_GLIBCXX_FILESYSTEM_IS_WINDOWS]: Convert root-dir to forward-slash.
* testsuite/27_io/filesystem/path/generic/generic_string.cc: Check
root-dir is converted to forward slash in generic pathname.
* testsuite/27_io/filesystem/path/generic/utf.cc: New test.
* testsuite/27_io/filesystem/path/generic/wchar_t.cc: New test.
PR libstdc++/58605
* include/bits/atomic_base.h (__cpp_lib_atomic_value_initialization):
Define.

View File

@ -1136,6 +1136,13 @@ namespace __detail
bool __add_slash = false;
for (auto& __elem : *this)
{
#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
if (__elem._M_type() == _Type::_Root_dir)
{
__str += __slash;
continue;
}
#endif
if (__add_slash)
__str += __slash;
__str += __elem._M_pathname;

View File

@ -46,8 +46,19 @@ test01()
VERIFY( path("/a//b//.").generic_string() == "/a/b/." );
}
void
test02()
{
// PR libstdc++/93244
path p("C:");
p += path::preferred_separator;
p += "foo/bar";
VERIFY( p.generic_string() == "C:/foo/bar" );
}
int
main()
{
test01();
test02();
}

View File

@ -0,0 +1,64 @@
// { dg-options "-std=gnu++17" }
// { dg-do run { target c++17 } }
// Copyright (C) 2017-2020 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// C++17 30.10.7.4.7 path generic format observers [fs.path.generic.obs]
#include <filesystem>
#include <testsuite_hooks.h>
using std::filesystem::path;
void
test01()
{
VERIFY( path().generic_u32string() == U"" );
VERIFY( path("/").generic_u32string() == U"/" );
VERIFY( path("////").generic_u32string() == U"/" );
#ifdef __CYGWIN__
VERIFY( path("//a").generic_u32string() == U"//a" );
VERIFY( path("//a/").generic_u32string() == U"//a/" );
VERIFY( path("//a/b").generic_u32string() == U"//a/b" );
#else
VERIFY( path("//a").generic_u32string() == U"/a" );
VERIFY( path("//a/").generic_u32string() == U"/a/" );
VERIFY( path("//a/b").generic_u32string() == U"/a/b" );
#endif
VERIFY( path("/a//b").generic_u32string() == U"/a/b" );
VERIFY( path("/a//b/").generic_u32string() == U"/a/b/" );
VERIFY( path("/a//b//").generic_u32string() == U"/a/b/" );
VERIFY( path("/a//b//.").generic_u32string() == U"/a/b/." );
}
void
test02()
{
// PR libstdc++/93244
path p("C:");
p += path::preferred_separator;
p += "foo/bar";
VERIFY( p.generic_u32string() == U"C:/foo/bar" );
}
int
main()
{
test01();
test02();
}

View File

@ -0,0 +1,64 @@
// { dg-options "-std=gnu++17" }
// { dg-do run { target c++17 } }
// Copyright (C) 2017-2020 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// C++17 30.10.7.4.7 path generic format observers [fs.path.generic.obs]
#include <filesystem>
#include <testsuite_hooks.h>
using std::filesystem::path;
void
test01()
{
VERIFY( path().generic_wstring() == L"" );
VERIFY( path("/").generic_wstring() == L"/" );
VERIFY( path("////").generic_wstring() == L"/" );
#ifdef __CYGWIN__
VERIFY( path("//a").generic_wstring() == L"//a" );
VERIFY( path("//a/").generic_wstring() == L"//a/" );
VERIFY( path("//a/b").generic_wstring() == L"//a/b" );
#else
VERIFY( path("//a").generic_wstring() == L"/a" );
VERIFY( path("//a/").generic_wstring() == L"/a/" );
VERIFY( path("//a/b").generic_wstring() == L"/a/b" );
#endif
VERIFY( path("/a//b").generic_wstring() == L"/a/b" );
VERIFY( path("/a//b/").generic_wstring() == L"/a/b/" );
VERIFY( path("/a//b//").generic_wstring() == L"/a/b/" );
VERIFY( path("/a//b//.").generic_wstring() == L"/a/b/." );
}
void
test02()
{
// PR libstdc++/93244
path p("C:");
p += path::preferred_separator;
p += "foo/bar";
VERIFY( p.generic_wstring() == L"C:/foo/bar" );
}
int
main()
{
test01();
test02();
}