https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93201
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> --- This shows the bug on trunk, which only affects the quality of error reporting when an error occurs: #include <fstream> #include <filesystem> using std::filesystem::path; using std::filesystem::perms; int main(int argc, char** argv) { if (argc < 2) return 1; path dir(argv[1]); std::error_code ec; create_directory(dir, ec); // ignore errors std::ofstream file{dir/"file"}; permissions(dir, perms::owner_read|perms::owner_exec); remove_all(dir); } $ ./a.out nonwritable terminate called after throwing an instance of 'std::filesystem::__cxx11::filesystem_error' what(): filesystem error: cannot remove all: Directory not empty [nonwritable] Aborted (core dumped) Instead of reporting a permission denied error it says the directory is not empty.