如何在clang 3.4中使用make_unique?

时间:2015-04-03 12:15:14

标签: c++ clang c++14

使用Travis-CI我尝试构建使用std::make_unique的C ++项目。但是我收到了构建错误:

no member named 'make_unique' in namespace 'std'
            mFiles.emplace_back(std::make_unique<File>(*this, rec));

我已添加memory,此代码在VS2013和gcc 4.8中编译-std=c++14。如果我在clang 3.4中使用此标志,则会出现错误:

error: invalid value 'c++14' in '-std=c++14'

根据clang docs:

http://clang.llvm.org/cxx_status.html

我应该使用-std=c++1y,但这仍然是no member named 'make_unique' in namespace 'std'。那么我该如何让它发挥作用呢?

1 个答案:

答案 0 :(得分:3)

这不依赖于编译器,而是依赖于标准库实现。 std::make_unique不是核心语言功能,而是库函数。

检查Travis使用的libstdc++版本。


根据the GCC 4.9 changelog,在{GCC 4.9'发布时std::make_unique引入libstdc++

如果Travis在4.9之前使用的是GCC版本,那么它的libstdc++版本很可能还没有std::make_unique