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.
system_error and filesystem_error constructors taking a string may not be able
to meet their postconditionsSection: 19.5.8.2 [syserr.syserr.members], 31.12.7.2 [fs.filesystem.error.members] Status: C++20 Submitter: Tim Song Opened: 2018-05-10 Last modified: 2021-06-06
Priority: 0
View all other issues in [syserr.syserr.members].
View all issues with C++20 status.
Discussion:
The constructors of system_error and filesystem_error taking a std::string what_arg
are specified to have a postcondition of string(what()).find(what_arg) != string::npos (or the equivalent with
string_view). This is not possible if what_arg contains an embedded null character.
[2019-01-20 Reflector prioritization]
Set Priority to 0 and status to Tentatively Ready
Proposed resolution:
This wording is relative to N4727.
Drafting note: This contains a drive-by editorial change to use
string_viewfor these postconditions rather thanstring.
Edit 19.5.8.2 [syserr.syserr.members] p1-4 as indicated:
system_error(error_code ec, const string& what_arg);-1- Effects: Constructs an object of class
-2- Postconditions:system_error.code() == ecandstring_view(what()).find(what_arg.c_str()) != string_view::npos.system_error(error_code ec, const char* what_arg);-3- Effects: Constructs an object of class
-4- Postconditions:system_error.code() == ecandstring_view(what()).find(what_arg) != string_view::npos.
Edit 19.5.8.2 [syserr.syserr.members] p7-10 as indicated:
system_error(int ev, const error_category& ecat, const std::string& what_arg);-7- Effects: Constructs an object of class
-8- Postconditions:system_error.code() == error_code(ev, ecat)andstring_view(what()).find(what_arg.c_str()) != string_view::npos.system_error(int ev, const error_category& ecat, const char* what_arg);-9- Effects: Constructs an object of class
-10- Postconditions:system_error.code() == error_code(ev, ecat)andstring_view(what()).find(what_arg) != string_view::npos.
Edit [fs.filesystem_error.members] p2-4 as indicated:
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.c_str()) != 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.c_str()) != 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,string_view(what()).find(what_arg.c_str()) != string_view::npos.