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.

### 3112. `system_error` and `filesystem_error` constructors taking a `string` may not be able to meet their postconditions

Section: 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_view` for these postconditions rather than `string`.

1. 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 `system_error`.

   > > -2- Postconditions: `code() == ec` and `string_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 `system_error`.

   > > -4- Postconditions: `code() == ec` and `string_view(what()).find(what_arg) != string_view::npos`.

2. 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 `system_error`.

   > > -8- Postconditions: `code() == error_code(ev, ecat)` and `string_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 `system_error`.

   > > -10- Postconditions: `code() == error_code(ev, ecat)` and `string_view(what()).find(what_arg) != string_view::npos`.

3. 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`, and
   > > - `string_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 of `p1`,
   > > - `path2().empty() == true`, and
   > > - `string_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 of `p1`,
   > > - `path2()` returns a reference to the stored copy of `p2`,
   > > - `string_view(what()).find(what_arg.c_str()) != string_view::npos`.