https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108859

            Bug ID: 108859
           Summary: Exception thrown by std::filesystem::copy() is wrong
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vini.ipsmaker at gmail dot com
  Target Milestone: ---

std::filesystem::filesystem_error::path1() and
std::filesystem::filesystem_error::path2() should contain the paths for the
most deeply-nested call, not the outermost call. It's discarding information
regarding the error that actually occurred.

#include <filesystem>
#include <iostream>

int main(int argc, char *argv[])
{
    try {
        std::filesystem::copy(std::filesystem::path{argv[1]},
                              std::filesystem::path{argv[2]},
                              std::filesystem::copy_options::recursive);
    } catch (const std::filesystem::filesystem_error& e) {
        std::cerr << e.what() << '\n' << e.path1() << '\n' << e.path2() <<
'\n';
    }
}

If a file already exists, path1() should not be argv[1], but the file that
failed to copy. Same for path2().
  • [Bug libstdc++/108859] New: Ex... vini.ipsmaker at gmail dot com via Gcc-bugs

Reply via email to