<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/151127>151127</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[regression, libcxx, C++26] __cpp_lib_filesystem is not available in libc++ until <fstream> is included
</td>
</tr>
<tr>
<th>Labels</th>
<td>
libc++
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
vedranmiletic
</td>
</tr>
</table>
<pre>
Consider the following code:
``` c++
#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
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVUGP4ygT_TXkUoqFIY7jgw_u5Iv0SXvbvUcYyjY7GCzAnfRlf_sKO93Tme7Z7ZXGQrJNQdV7VQ9KhKB7i1iT4okUp42Y4-B8_YzKCztqg1HLTevUS310NmiFHuKA0Dlj3FXbHqRTSHhD6DL2dB0gCXtKgzaEcd0p7OBykdN0Mbq9dNpgeAkRx7vdSjMrBMKP70z8f6sVrdLd3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