gpt4 book ai didi

c++ - Clang 拒绝编译 libstdc++ 的 header

转载 作者:太空狗 更新时间:2023-10-29 21:31:31 24 4
gpt4 key购买 nike

考虑这个最小的例子:

#include <filesystem>
#include <iostream>

int main()
{
std::cout << std::filesystem::current_path() << '\n';
}

它在 GCC 9.2 中按预期工作,但 Clang 8.0.1 拒绝编译 <filesystem> header (来自 GCC 9.2 的 libstdc++):

# clang++ 1.cpp -std=c++17
In file included from 1.cpp:1:
In file included from Z:\Lander\msys2\mingw64\include\c++\9.2.0\filesystem:37:
Z:\Lander\msys2\mingw64\include\c++\9.2.0\bits/fs_path.h:636:31: error: invalid use of incomplete
type 'std::filesystem::__cxx11::filesystem_error'
_GLIBCXX_THROW_OR_ABORT(filesystem_error(
^~~~~~~~~~~~~~~~~
Z:\Lander\msys2\mingw64\include\c++\9.2.0\x86_64-w64-mingw32\bits/c++config.h:177:49: note: expanded
from macro '_GLIBCXX_THROW_OR_ABORT'
# define _GLIBCXX_THROW_OR_ABORT(_EXC) (throw (_EXC))
^~~~
Z:\Lander\msys2\mingw64\include\c++\9.2.0\bits/fs_fwd.h:61:9: note: forward declaration of
'std::filesystem::__cxx11::filesystem_error'
class filesystem_error;
^
1 error generated.

这是 Clang 错误还是 libstdc++ 错误?

我找到了 this bug report在 MSYS2 错误跟踪器上,但其中没有有用的信息。

有没有办法修补<filesystem> header 来消除这个错误,而我们正在等待官方修复?


我在 Windows 上。我正在使用 MSYS2 软件包中提供的最新 GCC 和 Clang。

GCC 标识为:

# g++ --version
g++.exe (Rev2, Built by MSYS2 project) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Clang 标识为:

# clang++ --version
clang version 8.0.1 (tags/RELEASE_801/final)
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: Z:\Lander\msys2\mingw64\bin

Clang 使用此 GCC 附带的 libstdc++。

最佳答案

此问题可以通过修补 <msys2_path>/mingw64/include/c++/9.2.0/bits/fs_path.h 来解决.

在第 666-692 行,定义了 class filesystem_error .它必须向上移动到第 614 行,正好在 u8path() 的定义之上。 .


我认为这是一个 libstdc++ 错误。我已经举报了here .

class filesystem_errorbits/fs_path.h 中多次使用,并且除了有问题的第 636 行外,它的每次使用都在定义之下。

该行包含在 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 中,所以我猜 Clang 开发人员不会在 Windows 上运行 libstdc++ 兼容性测试。


UPD:这已在 GCC 9.3 中修复。

关于c++ - Clang 拒绝编译 libstdc++ 的 <filesystem> header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57963460/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com