【问题标题】:clang support of aggregation initialization on Mac OS X在 Mac OS X 上对聚合初始化的 clang 支持
【发布时间】:2013-06-01 22:01:04
【问题描述】:

我正在尝试在 mac 上的 clang++ 上编译 C++11 列表会众初始化。

#include <iostream>
#include <list>
#include <string>

using namespace std;
int main(int argc, char *argv[]) {
    list<string> aList = {"abc", "def", "xyz"};
}

这是编译命令。

clang++-mp-3.1 -std=c++11 iterator.cpp

我没有匹配的构造函数错误。

iterator.cpp:7:23: error: no matching constructor for initialization of
  'std::list<string>'
std::list<string> aList = {"abc", "def", "xyz"};
                  ^       ~~~~~~~~~~~~~~~~~~~~~

我试过 XCode

clang -v
Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.4.2
Thread model: posix

我也尝试使用来自端口的 clang++

clang++-mp-3.1 -v
clang version 3.1 (branches/release_31)
Target: x86_64-apple-darwin11.4.2
Thread model: posix

我得到了同样的结果。可能有什么问题?

clang's support of C++ 11 lambda

【问题讨论】:

  • 您使用过-std=c++11-std=c++0x 标志吗?
  • @H2CO3 :我有那个标志。
  • 来自 svn trunk 的 clang 编译你的代码。
  • 这不是聚合初始化。这是通过 initializer_list 构造函数进行的 uniform 初始化。
  • 另外,您使用的是什么版本的标准库实现?

标签: macos c++11 clang clang++


【解决方案1】:

我试过icc,得到了同样的错误。我想问题出在模板而不是编译器上。 icc 使用现有的模板 /usr/include/c++/4.2.1 并且实现不完全支持 c++11。

我从端口尝试了 gcc 4.8

sudo port install gcc48

效果很好

/opt/local/bin/g++-mp-4.8 -std=c++11 Iterator.cpp 

How to turn on C++0x of Intel C++ Compiler 12.1.2

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多