Skip to content

Use std::filesystem::path in place of std::string for file names #8721

@alexreinking

Description

@alexreinking

Compilers are finally starting to support std::filesystem without extra build requirements.

Compiler Version Godbolt
GCC 9.1+ https://gcc.godbolt.org/z/K4sWrPaKo
Clang 7.0.0+ https://gcc.godbolt.org/z/zn164jaMe
MSVC v19.20/VS16.0 https://gcc.godbolt.org/z/KE7YMe6Kz
AppleClang 17.0.0+ (at least) see details below
AppleClang on my personal MacBook
areinking@Mac ~ % cat test.cpp 
#include <filesystem>
#include <iostream>
#include <string_view>

int main(int argc, char* argv[]) {
    if (argc < 2) {
        return 1;
    }
    std::filesystem::path path = std::string_view{argv[1]};
    std::cout << "path = " << path << "\n";
    return 0;
}

areinking@Mac ~ % clang++ --version
Apple clang version 17.0.0 (clang-1700.0.13.5)
Target: arm64-apple-darwin24.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
areinking@Mac ~ % clang++ -std=c++17 test.cpp -o test
areinking@Mac ~ % ./test .
path = "."

Previously (i.e. on GCC <9.1) there were special linking requirements to get the filesystem libraries that affected downstreams. This does not appear to be the case any longer.

PR #8718 introduces a tiny reimplementation of std::filesystem::path just for the purpose of marshaling Path objects to and from Python. This can be replaced directly with the standard type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    code_cleanupNo functional changes. Reformatting, reorganizing, or refactoring existing code.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions