I am using clang++, installed with MSYS2 on Windows 11. Checking the version of clang++ gives the below.
~ clang++ --version
clang version 19.1.4
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: C:/msys64/mingw64/bin
The code:
#include <filesystem>
int main(){
std::filesystem::path p = "C:/Users/Jaden/Documents/hi.txt";
std::filesystem::path p2 = "C:/Users/Jaden";
std::filesystem::copy(
p, p2, std::filesystem::copy_options::overwrite_existing);
}
Produces the error:
terminate called after throwing an instance of 'std::filesystem::__cxx11::filesystem_error'
what(): filesystem error: cannot copy: File exists [C:/Users/Jaden/Documents/hi.txt] [C:/Users/Jaden]
If I run std::filesystem::exists beforehand, it returns false. The error persists no matter if I use or do not use and copy_option flags.
The code was simply compiled with clang++ .\test.cpp.
Edit: Similarly when I compile using g++, the same issue persists.
After some testing, this is a bug in libstdc++, the GCC's C++ standard library. It's already fixed in the newer versions.
This happens any time you do std::filesystem::copy("file", "directory"), regardless of overwrite_existing.
I've reported it here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118699, and was told that it's fixed in 15.x, 14.3.0, and 13.4.0, while MSYS2 still sits at 14.2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With