This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++20 status.
filesystem_error
constructorSection: 31.12.7.2 [fs.filesystem.error.members] Status: C++20 Submitter: Tim Song Opened: 2017-12-06 Last modified: 2021-06-06
Priority: 0
View all other issues in [fs.filesystem.error.members].
View all issues with C++20 status.
Discussion:
[fs.filesystem_error.members] says that constructors of
filesystem_error
have the postcondition that runtime_error::what()
has the
value what_arg.c_str()
. That's obviously incorrect: these are pointers
to distinct copies of the string in any sane implementation and cannot
possibly compare equal.
runtime_error::what()
, but filesystem_error
has no direct control over the construction of its indirect
non-virtual base class runtime_error
. Instead, what is passed to runtime_error
's
constructor is determined by system_error
's constructor, which in many implementations
is an eagerly crafted error string. This is permitted by the specification of
system_error
(see 19.5.8 [syserr.syserr]) but would make the requirement unimplementable.
The proposed wording below adjusts the postcondition using the formula of system_error
's
constructor. As an editorial change, it also replaces the postcondition tables with normal postcondition clauses,
in the spirit of editorial issue 1875.
[ 2018-01-12 Moved to Tentatively Ready after 5 positive votes on c++std-lib. ]
[2018-3-17 Adopted in Jacksonville]
Proposed resolution:
This wording is relative to N4713.
Replace [fs.filesystem_error.members] p2-4, including Tables 119 through 121, with the following:
filesystem_error(const string& what_arg, error_code ec);
-2- Postconditions:code() == ec
,path1().empty() == true
,path2().empty() == true
, andstring_view(what()).find(what_arg) != string_view::npos
.
filesystem_error(const string& what_arg, const path& p1, error_code ec);
-3- Postconditions:code() == ec
,path1()
returns a reference to the stored copy ofp1
,path2().empty() == true
, andstring_view(what()).find(what_arg) != string_view::npos
.
filesystem_error(const string& what_arg, const path& p1, const path& p2, error_code ec);
-4- Postconditions:code() == ec
,path1()
returns a reference to the stored copy ofp1
,path2()
returns a reference to the stored copy ofp2
, andstring_view(what()).find(what_arg) != string_view::npos
.
Edit [fs.filesystem_error.members] p7 as indicated:
const char* what() const noexcept override;
-7- Returns:A string containingAn ntbs that incorporates theruntime_error::what()
.what_arg
argument supplied to the constructor. The exact format is unspecified. Implementations should include thesystem_error::what()
string and the pathnames ofpath1
andpath2
in the native format in the returned string.