Skip to content

[regression, libcxx, C++26] __cpp_lib_filesystem is not available in libc++ until <fstream> is included #151127

@vedranmiletic

Description

@vedranmiletic

Consider the following code:

#ifdef __cpp_lib_filesystem
#include <filesystem>
#endif

#include <fstream>

int main() {
#ifdef __cpp_lib_filesystem
  auto path = std::filesystem::current_path().string();
#endif
  return 0;
}

Compiling in C++23 mode works both with Clang 19 and 20 (version details below):

clang++ -std=c++23 -stdlib=libc++ fs.cpp

Compiling in C++26 mode fails with the following error:

$ clang++ -std=c++26 -stdlib=libc++ fs.cpp
fs.cpp:9:30: error: no member named 'current_path' in namespace 'std::filesystem'
    9 | auto path = std::filesystem::current_path().string();
      |             ~~~~~~~~~~~~~~~~~^
1 error generated.

only when using Clang 20 on Arch Linux:

$ clang++ --version
clang version 20.1.8
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

but compiles fine when using Clang 19 on FreeBSD:

% clang++ --version
FreeBSD clang version 19.1.7 (https://github.com/llvm/llvm-project.git llvmorg-19.1.7-0-gcd708029e0b2)
Target: x86_64-unknown-freebsd14.3
Thread model: posix
InstalledDir: /usr/bin

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidResolved as invalid, i.e. not a buglibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions