Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filesystem::u8path should accept char8_t sources #1943

Merged
merged 4 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions stl/inc/filesystem
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ namespace filesystem {

template <class _Conversion>
_NODISCARD wstring _Convert_stringoid_to_wide(const string_view _Input, _Conversion) {
static_assert(_Is_any_of_v<_Conversion, _Normal_conversion, _Utf8_conversion>);
_STL_INTERNAL_STATIC_ASSERT(_Is_any_of_v<_Conversion, _Normal_conversion, _Utf8_conversion>);

if constexpr (is_same_v<_Conversion, _Normal_conversion>) {
return _Convert_narrow_to_wide(__std_fs_code_page(), _Input);
Expand All @@ -275,8 +275,8 @@ namespace filesystem {
#ifdef __cpp_char8_t
template <class _Conversion>
_NODISCARD wstring _Convert_stringoid_to_wide(const basic_string_view<char8_t> _Input, _Conversion) {
static_assert(
is_same_v<_Conversion, _Normal_conversion>, "invalid value_type, see N4810 D.17 [depr.fs.path.factory]/1");
_STL_INTERNAL_STATIC_ASSERT(_Is_any_of_v<_Conversion, _Normal_conversion, _Utf8_conversion>);

const string_view _Input_as_char{reinterpret_cast<const char*>(_Input.data()), _Input.size()};
return _Convert_narrow_to_wide(__std_code_page::_Utf8, _Input_as_char);
}
Expand Down
32 changes: 22 additions & 10 deletions tests/std/tests/P1423R3_char8_t_remediation/test.compile.pass.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#define _SILENCE_CXX20_U8PATH_DEPRECATION_WARNING 1
#include <filesystem>
#include <ostream>
#include <string_view>
#include <type_traits>
#include <utility>

Expand All @@ -21,7 +24,7 @@ STATIC_ASSERT(stream_insertable<std::ostream, int&>);
STATIC_ASSERT(stream_insertable<std::ostream, const int&>);

template <class Stream, class charT>
constexpr bool test() {
constexpr bool test_stream_insertion() {
// validate that expressions of type (possibly-const) charT and (possibly-const) charT* (possibly-const) are
// equivalently insertable into Stream
constexpr bool result = stream_insertable<Stream, charT>;
Expand All @@ -45,18 +48,27 @@ constexpr bool test() {
}

// Control cases
STATIC_ASSERT(test<std::ostream, char>());
STATIC_ASSERT(test<std::wostream, wchar_t>());
STATIC_ASSERT(test_stream_insertion<std::ostream, char>());
STATIC_ASSERT(test_stream_insertion<std::wostream, wchar_t>());

#ifdef __cpp_char8_t
STATIC_ASSERT(!test<std::ostream, char8_t>());
STATIC_ASSERT(!test<std::wostream, char8_t>());
STATIC_ASSERT(!test_stream_insertion<std::ostream, char8_t>());
STATIC_ASSERT(!test_stream_insertion<std::wostream, char8_t>());
#endif // __cpp_char8_t

#ifdef _NATIVE_WCHAR_T_DEFINED
STATIC_ASSERT(test<std::ostream, wchar_t>() == !_HAS_CXX20);
STATIC_ASSERT(test_stream_insertion<std::ostream, wchar_t>() == !_HAS_CXX20);
#endif // _NATIVE_WCHAR_T_DEFINED
STATIC_ASSERT(test<std::ostream, char16_t>() == !_HAS_CXX20);
STATIC_ASSERT(test<std::ostream, char32_t>() == !_HAS_CXX20);
STATIC_ASSERT(test<std::wostream, char16_t>() == !_HAS_CXX20);
STATIC_ASSERT(test<std::wostream, char32_t>() == !_HAS_CXX20);
STATIC_ASSERT(test_stream_insertion<std::ostream, char16_t>() == !_HAS_CXX20);
STATIC_ASSERT(test_stream_insertion<std::ostream, char32_t>() == !_HAS_CXX20);
STATIC_ASSERT(test_stream_insertion<std::wostream, char16_t>() == !_HAS_CXX20);
STATIC_ASSERT(test_stream_insertion<std::wostream, char32_t>() == !_HAS_CXX20);

#ifdef __cpp_char8_t
void test_u8path() {
(void) std::filesystem::u8path(u8"a");
const std::basic_string_view sv{u8"a"};
(void) std::filesystem::u8path(sv);
(void) std::filesystem::u8path(sv.begin(), sv.end());
}
#endif // __cpp_char8_t