【问题标题】:why doesn't clang++ compile the following code?为什么clang++不编译下面的代码?
【发布时间】:2014-05-30 19:45:24
【问题描述】:

我有以下代码:

#include <type_traits>

int main()
{
}

g++ 文件.cc -std=c++0x

工作得很好。

但是,由于某种原因,我需要使用 clang++。

当我尝试时

clang++ file.cc -std=c++0x

我收到一堆错误:

In file included from file.cc:1:
In file included from /usr/include/c++/4.4.4/type_traits:50:
/usr/include/c++/4.4.4/tr1_impl/type_traits:230:41: error: expected ')'
    struct is_function<_Res(_ArgTypes......)>
                                        ^
/usr/include/c++/4.4.4/tr1_impl/type_traits:230:28: note: to match this '('
    struct is_function<_Res(_ArgTypes......)>
                           ^
/usr/include/c++/4.4.4/tr1_impl/type_traits:230:12: error: redefinition of 'is_function<type-parameter-0-0 (type-parameter-0-1, ...)>'
    struct is_function<_Res(_ArgTypes......)>
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/4.4.4/tr1_impl/type_traits:227:12: note: previous definition is here
    struct is_function<_Res(_ArgTypes...)>
           ^
/usr/include/c++/4.4.4/tr1_impl/type_traits:233:29: error: type qualifier is not allowed on this function
    struct is_function<_Res(_ArgTypes...) const>
....

clang++ --version 给出:

clang version 2.8 (branches/release_28)
Target: x86_64-redhat-linux-gnu
Thread model: posix

任何想法如何解决这个问题? (-std=c++11 不起作用,无法识别。)

【问题讨论】:

  • 我建议升级 Clang。
  • @chris 不是我的服务器...有什么办法可以使用当前版本?虽然我会要求升级它,但可能需要一些时间。
  • 你必须在你的 main 中添加一个 return 语句
  • @Bruno,根据 C++ 的每个 ISO 标准,你不知道。
  • @kloop 您的 clang 版本太旧了。请参阅我之前关于 TR1 的评论,除了升级编译器之外,这可能是您唯一的选择

标签: c++ linux c++11


【解决方案1】:

Clang 2.8 不支持 C++11 功能,您需要升级编译器才能使用它们。

【讨论】:

  • 那么为什么我没有得到 -std=c++0x 的错误?如果我尝试除此之外的其他方法,我会收到错误消息(不支持的语言或类似的东西。)
  • @kloop 不要使用type_traits。手动重写你需要的函数。它们没有那么复杂。这是您使用过时的编译器唯一可以做的事情。
  • @kloop 我猜添加了兼容性标志,但正如您所见here,至少在 Clang2.9 之前,clang 基本上不支持 C++11。只要您的编译器没有-c++11 标志,您就必须预料到会出现重大问题。
  • @Malloc 谢谢。我想根据大家的建议,最好的办法是升级 clang。
  • @polkovnikov.ph 这个问题真的出现在#include ,它包括type_traits。那只是一个 MWE。
猜你喜欢
  • 2017-01-11
  • 2017-11-09
  • 1970-01-01
  • 2012-05-28
  • 1970-01-01
  • 1970-01-01
  • 2013-02-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多