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.

### 3014. More `noexcept` issues with filesystem operations

Section: 31.12.13.5 [fs.op.copy.file], 31.12.13.7 [fs.op.create.directories], 31.12.13.32 [fs.op.remove.all] Status: C++20 Submitter: Tim Song Opened: 2017-08-23 Last modified: 2021-06-06

Priority: Not Prioritized

View all other issues in [fs.op.copy.file].

View all issues with C++20 status.

Discussion:

`create_directories` may need to create temporary `path`s, and `remove_all` may need to create temporary `path`s and/or `directory_iterator`s. These operations may require a potentially throwing memory allocation.

Implementations of `copy_file` may wish to dynamically allocate the buffer used for copying when the underlying OS doesn't supply a copy API directly. This can happen indirectly, e.g., by using `<fstream>` facilities to perform the copying without supplying a custom buffer. Unless LWG wishes to prohibit using a dynamically allocated buffer in this manner, the `noexcept` should be removed.

[2017-11 Albuquerque Wednesday night issues processing]

Moved to Ready

[2018-3-17 Adopted in Jacksonville]

Proposed resolution:

This wording is relative to N4687.

1. Edit 31.12.4 [fs.filesystem.syn], header `<filesystem>` synopsis, as indicated:

   >     namespace std::filesystem {

   >       […]

   >       bool copy_file(const path& from, const path& to);
   >       bool copy_file(const path& from, const path& to, error_code& ec) noexcept;
   >       bool copy_file(const path& from, const path& to, copy_options option);
   >       bool copy_file(const path& from, const path& to, copy_options option,
   >                      error_code& ec) noexcept;

   >       […]

   >       bool create_directories(const path& p);
   >       bool create_directories(const path& p, error_code& ec) noexcept;

   >       […]

   >       uintmax_t remove_all(const path& p);
   >       uintmax_t remove_all(const path& p, error_code& ec) noexcept;

   >       […]
   >     }

2. Edit [fs.op.copy_file] as indicated:

   >     bool copy_file(const path& from, const path& to);
   >     bool copy_file(const path& from, const path& to, error_code& ec) noexcept;

   > > -1- Returns: […]

   > > -2- Throws: […]

   >     bool copy_file(const path& from, const path& to, copy_options options);
   >     bool copy_file(const path& from, const path& to, copy_options options,
   >                    error_code& ec) noexcept;

   > > -3- Requires: […]

   > > -4- Effects: […]

   > > -5- Returns: […]

   > > -6- Throws: […]

   > > -7- Complexity: […]

3. Edit [fs.op.create_directories] as indicated:

   >     bool create_directories(const path& p);
   >     bool create_directories(const path& p, error_code& ec) noexcept;

   > > -1- Effects: […]

   > > -2- Postconditions: […]

   > > -3- Returns: […]

   > > -4- Throws: […]

   > > -5- Complexity: […]

4. Edit [fs.op.remove_all] as indicated:

   >     uintmax_t remove_all(const path& p);
   >     uintmax_t remove_all(const path& p, error_code& ec) noexcept;

   > > -1- Effects: […]

   > > -2- Postconditions: […]

   > > -3- Returns: […]

   > > -4- Throws: […]