admin管理员组文章数量:1316852
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.
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.
Share Improve this question edited Jan 29 at 20:17 JadenJin asked Jan 29 at 20:07 JadenJinJadenJin 931 silver badge4 bronze badges 5 |1 Answer
Reset to default 5After 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./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.
本文标签: cMSYS2 Clang produces error with filesystem libraryStack Overflow
版权声明:本文标题:c++ - MSYS2 Clang++ produces error with filesystem library - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741999412a2410703.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
hi.txt
to a subdirectory ofDocuments
? Anything change if you use MSYS2-style paths (/c/Users/Jaden/Documents/hi.txt
)? – genpfault Commented Jan 29 at 20:20"C:/Users/Jaden/hi.txt"
behaves as expected. – user4581301 Commented Jan 29 at 20:26copy_file(from, to/from.filename(), options)
(creates a copy of from as a file in the directory to) which reads to me as this should work, but in the modern Windows world of groovy virtual folders representing other folders (sometimes in cloud storage) is the user folder REALLY a folder? – user4581301 Commented Jan 29 at 20:43File exists [D:/test/a/hi.txt] [D:/test/b]
– user4581301 Commented Jan 29 at 20:46