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

            Bug ID: 71415
           Summary: std::filesystem::exists that does not throw sets error
                    code if file does not exist
           Product: gcc
           Version: 6.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marejde at gmail dot com
  Target Milestone: ---

The following program:

#include <experimental/filesystem>
#include <iostream>

int main(int argc, char *argv[])
{
        std::error_code error_code;
        bool exists = std::experimental::filesystem::exists("does_not_exist",
error_code);

        std::cout << "exists: " << exists << '\n';
        std::cout << "error_code.value(): " << error_code.value() << '\n';
        std::cout << "error_code.message(): " << error_code.message() << '\n';
        std::cout << "error_code operator bool: " << (error_code.value() ? true
: false) << '\n';

        return 0;
}

outputs:

exists: 0
error_code.value(): 2
error_code.message(): No such file or directory
error_code operator bool: 1

Which means it is not possible to discern between an error and when the file
does not exist without examining error_code.value(), which is platform
dependent.

Tested on Arch Linux with "gcc (GCC) 6.1.1 20160501".

Reply via email to