path::native_string()
in filesystem_error::what()
specificationSection: 31.12.7.2 [fs.filesystem.error.members] Status: C++20 Submitter: Daniel Krügler Opened: 2017-05-22 Last modified: 2021-06-06
Priority: 0
View all other issues in [fs.filesystem.error.members].
View all issues with C++20 status.
Discussion:
As pointed out by Jonathan Wakely and Bo Persson, [filesystem_error.members]/7 refers to a non-existing
function path::native_string
:
Returns: A string containing
runtime_error::what()
. The exact format is unspecified. Implementations are encouraged but not required to includepath1.native_string()
if not empty,path2.native_string()
if not empty, andsystem_error::what()
strings in the returned string.
Existing implementations differ, as Jonathan also determined:
Boost.Filesystem uses path::string()
.
Libstdc++ uses path::string()
.
MSVC++/Dinkumware uses path::u8string()
.
It seems that libc++ doesn't include the paths in what()
.
We've had native_string()
in the spec since N3239 (where
it already didn't match any existing path
function at that time).
file_string()
in N1975
(within that specification path
was a template that was parametrized in the character type).
Since it can't be path::native()
because that might be the wrong type, one of path::string()
or
path::u8string()
seems appropriate.
Albeit the wording is just a non-binding encouragement to implementations, the decision on this matter should not be
considered editorially due to the existing implementation variance. Any official resolution of the current state could
cause a reconsideration of existing implementations, and therefore it should be documented.
Previous resolution [SUPERSEDED]:
This wording is relative to N4659.
Edit [filesystem_error.members] as indicated:
const char* what() const noexcept override;-7- Returns: A string containing
runtime_error::what()
. The exact format is unspecified. Implementations are encouraged but not required to includepath1.
if not empty,native_string()path2.
if not empty, andnative_string()system_error::what()
strings in the returned string.
[2017-05-25, Jonathan comments and suggests an alternative resolution]
The revised wording changes leave it up to the implementation which of the native format observers to use. The "if not empty" seems redundant, because if the path is empty then there's nothing to include anyway, but the proposed resolution preserves it.
[2017-07 Toronto Monday issue prioritization]
Priority 0; move to Ready
Proposed resolution:
This wording is relative to N4659.
Edit [filesystem_error.members] as indicated:
const char* what() const noexcept override;-7- Returns: A string containing
runtime_error::what()
. The exact format is unspecified. Implementations are encouraged but not required to includethepath1.native_string()
if not empty,path2.native_string()
if not empty, andsystem_error::what()
stringssystem_error::what()
string and the pathnames ofpath1
andpath2
in the native format in the returned string.