c++ - <experimental/any> 上的 clang++ 错误

标签 c++ clang

编译包含 <experimental/any> 的代码时出现错误.

main.cpp 中的代码:

#include <experimental/any>
int main() { }

编译这个(clang 版本是 3.9):

clang++ main.cpp -o main -std=c++1z

编译后报错:

In file included from main.cpp:2:
/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/experimental/any:364:34: error: 
      no template named '__any_caster'; did you mean 'any_cast'?
        return static_cast<_ValueType*>(__any_caster<_ValueType>(__any));
                                        ^
/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/experimental/any:361:30: note: 
      'any_cast' declared here
    inline const _ValueType* any_cast(const any* __any) noexcept
                             ^
/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/experimental/any:372:34: error: 
      no template named '__any_caster'; did you mean 'any_cast'?
        return static_cast<_ValueType*>(__any_caster<_ValueType>(__any));
                                        ^
/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/experimental/any:369:24: note: 
      'any_cast' declared here
    inline _ValueType* any_cast(any* __any) noexcept
                       ^
2 errors generated.

最佳答案

作为@chriscomments中提到:

You could try with libc++. Perhaps there's an incompatibility with Clang in libstdc++'s new header.

事实证明这是真的。 Clang 3.9 仍处于实验阶段,因此它使用实验性 header ,包括实验性 C++ 标准库。默认情况下,它由 GCC 提供,因此 GCC 实现与 Clang 实现之间存在不兼容问题。

关于c++ - <experimental/any> 上的 clang++ 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39352592/

相关文章:

从 LLVM 位码编译对象时无法链接到静态库。

c++ - 为 LLVM libc++ 3.3 构建静态库和共享库

objective-c - Xcode 存档 clang : error: cannot specify -o when generating multiple output files

c++ - 平滑离散数据

c++ - 是什么导致这些链接器错误? (Visual C++ LNK2005)

c++ - clang with -Weverything 标志没有捕获 vector 中不存在的元素

c++ - 允许 32 位应用程序在 FreeBSD 下使用超过 4GB 的内存

c++ - 在 C++ 中使用 istringstream 将字符串拆分为整数

c++ - OpenMPI MPI_Send 与 Intel MPI MPI_Send

c++ - 类型 'long long int' 到二进制 'operator%' 的无效操作数