Xcode/clang 更新后不再编译 C++14 代码 Xcode:"no member named make_shared"

Xcode/clang no longer compiling C++14 code after updating Xcode: "no member named make_shared"

我在一段时间后回到它后无法再构建我的 C++ 项目(我已经更新了 macOS 和 Xcode),无论是从 Xcode 还是通过调用 clang命令行。我在代码中每次使用 std::shared_ptr::make_shared 时都会出错。我想强调 this used to compile and 运行 fine and I don’t understand what has changed.也许更新 xcode 以某种方式破坏了我的工具链。

我在一些非常琐碎的代码中重现了这个问题,我认为应该可以正常编译:

#include <string>
#include <memory>

class test_c {
    private:
        std::string str_;
    
    public:
        test_c(std::string str__) : str_(str__) { }
};

std::string test_s = "test";
auto test = std::shared_ptr<test_c>::make_shared(test_s);

错误如下所示:

$ clang -std=c++14 test.cpp
test.cpp:10:38: error: no member named 'make_shared' in 'std::__1::shared_ptr<test_c>'
auto test = std::shared_ptr<test_c>::make_shared(test_s);
            ~~~~~~~~~~~~~~~~~~~~~~~~~^
1 error generated.

我根本找不到任何方法将 make_shared 作为静态方法调用。还检查了旧版本 Clang 中的其他代码。好像不行...

也许只是:

auto test = std::make_shared<test_c>(test_s);

UPD 等待。它确实在 clang of version 9 中起作用。看起来它确实已更新以禁用此功能...... 无法在 v10.

工作