c++ - 如何修复 lib libstdc+ +'s ` std::variant`(来自 GCC 9.1)不适用于 Clang 8?

标签 c++ clang clang++ libstdc++

MSYS2 的 GCC 软件包最近更新到了 9.1,但 Clang 不喜欢新的 <variant>附带的 libstdc++ header 。

编译以下简单程序时:

#include <variant>

int main()
{
    std::variant<int, float> x;
}

我得到:

# clang++ -std=c++17 foo.cpp

In file included from foo.cpp:1:
Z:\...\msys2\mingw64\include\c++\9.1.0\variant:1559:55: error: '__get' is missing exception specification 'noexcept'
        friend constexpr decltype(auto) __detail::__variant::__get(_Vp&& __v);
                                                             ^
foo.cpp:5:30: note: in instantiation of template class 'std::variant<int, float>' requested here
    std::variant<int, float> x;
                             ^
Z:\...\msys2\mingw64\include\c++\9.1.0\variant:263:5: note: previous declaration is here
    __get(_Variant&& __v) noexcept
    ^
1 error generated.

Here is the complete <variant> header if you want to look at it.

当我等待官方修复时,我按照 Clang 的建议做了并添加了 noexcept到标题。

到目前为止,它似乎有效。

此解决方案会导致任何问题吗?我应该做点别的吗?

如果您知道它是 libstdc++ bug 还是 Clang bug,则会加分。

最佳答案

修复是正确的。这是一个 libstdc++ 错误,请参阅 https://bugs.llvm.org/show_bug.cgi?id=41863https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90397

关于c++ - 如何修复 lib libstdc+ +'s ` std::variant`(来自 GCC 9.1)不适用于 Clang 8?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56485348/

相关文章:

c++ - 正在使用未初始化的变量 C++

c++ - 如何检查显示器是否已插入? (Linux)

c++ - 抽象指向成员函数的指针 : safety and alternatives

clang - 从 clang 匹配回调中获取方法调用的参数

c++ - 未知的 CMake 命令 "add_clang_executable"

linker-errors - clang++ -stdlib = libc++导致 undefined reference

c++ - 使用 Qt 内存管理时对 clang 静态分析的误报

c++ - 铿锵W旗令

vim - 如何使用 coc-clangd 在 vi​​m 中使用 lib gtk 进行 C 编程?

python - LLVM clang 的 CMake 构建失败并显示 "Unexpected failure executing llvm-build: Traceback (...) import llvmbuild"