来自 std::filesystem::u8path(const char8_t*) 的 VS 错误
VS error from std::filesystem::u8path(const char8_t*)
在这个简单的 C++20 程序中
#define _SILENCE_CXX20_U8PATH_DEPRECATION_WARNING //suppress VS warning
#include <filesystem>
int main()
{
auto p = std::filesystem::u8path(u8"a");
}
我在 stdcpplatest
模式下从 Visual Studio 2019 16.10.0 得到错误:
1>C:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Tools\MSVC.29.30037\include\filesystem(279,13): error C2338: invalid value_type, see N4810 D.17 [depr.fs.path.factory]/1
1>C:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Tools\MSVC.29.30037\include\filesystem(346): message : see reference to function template instantiation 'std::wstring std::filesystem::_Convert_stringoid_to_wide<_Conversion>(const std::basic_string_view<char8_t,std::char_traits<char8_t>>,_Conversion)' being compiled
1> with
1> [
1> _Conversion=std::filesystem::_Utf8_conversion
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Tools\MSVC.29.30037\include\filesystem(1442): message : see reference to function template instantiation 'std::wstring std::filesystem::_Convert_Source_to_wide<char8_t[2],std::filesystem::_Utf8_conversion>(const _Src (&),_Conversion)' being compiled
1> with
1> [
1> _Src=char8_t [2],
1> _Conversion=std::filesystem::_Utf8_conversion
1> ]
1>test.cpp(298): message : see reference to function template instantiation 'std::filesystem::path std::filesystem::u8path<char8_t[2],0>(const _Src (&))' being compiled
1> with
1> [
1> _Src=char8_t [2]
1> ]
除了 c++20 中 u8path
函数的弃用,我在这里没有发现任何错误,并且代码在 gcc 11 和 clang 12 中使用选项 -std=c++20 -Wall
编译得很好,没有任何警告。请大家帮忙看看哪里出了问题。
u8path
使用 char8_t
的能力是对 C++20 标准的一个相对较晚的添加。有问题的错误引用 N4810,这是一个包含 char8_t
的草稿(以及 filesystem::path
构造函数的重载),但草稿写在 之前 u8path
改为采用 char8_t
个字符串。
所以VS根本没有实现current version of that part of the standard。
当 P0482 (char8_t: A type for UTF-8 characters and strings) was adopted for C++20, it unintentionally resulted in std::filesystem::u8path()
no longer accepting u8
prefixed string literals (or char8_t
-based strings in general). This was an oversight by the author (me) that was corrected (for C++20) via P1423 (char8_t backward compatibility remediation). Microsoft claims to have implemented P1423 in VS 2019 16.6 (19.26), but it seems not so for at least this part of that proposal. Testing on godbolt.org 演示 VS 2019 16.2 (19.22) 到 VS 2019 16.8 (19.28) 和最新预览版时,所有拒绝调用带有 u8
前缀字符串文字的 std::filesystem::u8path()
当使用 /std:c++latest
编译时(gcc、clang 和 icc 都在其 C++20 一致性模式下接受测试)。
Github 用户 fsb4000 已 already reported this issue 给 Microsoft STL 维护者(显然是为了响应此 Whosebug post)。
在这个简单的 C++20 程序中
#define _SILENCE_CXX20_U8PATH_DEPRECATION_WARNING //suppress VS warning
#include <filesystem>
int main()
{
auto p = std::filesystem::u8path(u8"a");
}
我在 stdcpplatest
模式下从 Visual Studio 2019 16.10.0 得到错误:
1>C:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Tools\MSVC.29.30037\include\filesystem(279,13): error C2338: invalid value_type, see N4810 D.17 [depr.fs.path.factory]/1
1>C:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Tools\MSVC.29.30037\include\filesystem(346): message : see reference to function template instantiation 'std::wstring std::filesystem::_Convert_stringoid_to_wide<_Conversion>(const std::basic_string_view<char8_t,std::char_traits<char8_t>>,_Conversion)' being compiled
1> with
1> [
1> _Conversion=std::filesystem::_Utf8_conversion
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Tools\MSVC.29.30037\include\filesystem(1442): message : see reference to function template instantiation 'std::wstring std::filesystem::_Convert_Source_to_wide<char8_t[2],std::filesystem::_Utf8_conversion>(const _Src (&),_Conversion)' being compiled
1> with
1> [
1> _Src=char8_t [2],
1> _Conversion=std::filesystem::_Utf8_conversion
1> ]
1>test.cpp(298): message : see reference to function template instantiation 'std::filesystem::path std::filesystem::u8path<char8_t[2],0>(const _Src (&))' being compiled
1> with
1> [
1> _Src=char8_t [2]
1> ]
除了 c++20 中 u8path
函数的弃用,我在这里没有发现任何错误,并且代码在 gcc 11 和 clang 12 中使用选项 -std=c++20 -Wall
编译得很好,没有任何警告。请大家帮忙看看哪里出了问题。
u8path
使用 char8_t
的能力是对 C++20 标准的一个相对较晚的添加。有问题的错误引用 N4810,这是一个包含 char8_t
的草稿(以及 filesystem::path
构造函数的重载),但草稿写在 之前 u8path
改为采用 char8_t
个字符串。
所以VS根本没有实现current version of that part of the standard。
当 P0482 (char8_t: A type for UTF-8 characters and strings) was adopted for C++20, it unintentionally resulted in std::filesystem::u8path()
no longer accepting u8
prefixed string literals (or char8_t
-based strings in general). This was an oversight by the author (me) that was corrected (for C++20) via P1423 (char8_t backward compatibility remediation). Microsoft claims to have implemented P1423 in VS 2019 16.6 (19.26), but it seems not so for at least this part of that proposal. Testing on godbolt.org 演示 VS 2019 16.2 (19.22) 到 VS 2019 16.8 (19.28) 和最新预览版时,所有拒绝调用带有 u8
前缀字符串文字的 std::filesystem::u8path()
当使用 /std:c++latest
编译时(gcc、clang 和 icc 都在其 C++20 一致性模式下接受测试)。
Github 用户 fsb4000 已 already reported this issue 给 Microsoft STL 维护者(显然是为了响应此 Whosebug post)。