clang++ error on

2019-07-24 16:36发布

问题:

I get an error when compile code containing <experimental/any>.

Code in main.cpp:

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

Compile this (clang version is 3.9):

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

Error after the compiling:

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.

回答1:

As @chris mentioned in the comments:

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

This turns out to be true. Clang 3.9 is still experimental, and so it uses experimental headers, including a experimental C++ standard library. By default, it is provided by GCC, and so an incompatibility occurs between the GCC implementation and the Clang implementation.



标签: c++ clang