The create_dir helper was calling the throwing form of filesystem::is_directory instead of passing the error_code argument. Since std::filesystem::create_directory(const path&, error_code&) is noexcept, it would call std::terminate if an error occurred in is_directory.
Passing the error_code also takes care of clearing it in the case where is_directory returns true. src/filesystem/ops.cc (create_dir): Pass error_code to is_directory. src/filesystem/std-ops.cc (create_dir): Likewise. Tested powerpc64le-linux, committed to trunk.
commit c3ac5f5cbb2ce9d20c30da06d19bcdca20630e0b Author: Jonathan Wakely <jwak...@redhat.com> Date: Fri Mar 9 00:42:20 2018 +0000 Use non-throwing is_directory in filesystem::create_directory The create_dir helper was calling the throwing form of filesystem::is_directory instead of passing the error_code argument. Since std::filesystem::create_directory(const path&, error_code&) is noexcept, it would call std::terminate if an error occurred in is_directory. Passing the error_code also takes care of clearing it in the case where is_directory returns true. src/filesystem/ops.cc (create_dir): Pass error_code to is_directory. src/filesystem/std-ops.cc (create_dir): Likewise. diff --git a/libstdc++-v3/src/filesystem/ops.cc b/libstdc++-v3/src/filesystem/ops.cc index 899defea6d2..328332a8a82 100644 --- a/libstdc++-v3/src/filesystem/ops.cc +++ b/libstdc++-v3/src/filesystem/ops.cc @@ -463,10 +463,8 @@ namespace if (::mkdir(p.c_str(), mode)) { const int err = errno; - if (err != EEXIST || !is_directory(p)) + if (err != EEXIST || !is_directory(p, ec)) ec.assign(err, std::generic_category()); - else - ec.clear(); } else { diff --git a/libstdc++-v3/src/filesystem/std-ops.cc b/libstdc++-v3/src/filesystem/std-ops.cc index 65b06f5b67b..930b186e88c 100644 --- a/libstdc++-v3/src/filesystem/std-ops.cc +++ b/libstdc++-v3/src/filesystem/std-ops.cc @@ -668,10 +668,8 @@ namespace if (::mkdir(p.c_str(), mode)) { const int err = errno; - if (err != EEXIST || !is_directory(p)) + if (err != EEXIST || !is_directory(p, ec)) ec.assign(err, std::generic_category()); - else - ec.clear(); } else {