C++中的参数查找

Use*_*050 8 c++ gcc c++14

使用c ++ 14遇到gcc问题.编译下面的代码时,我收到一个错误

"call of overloaded ‘make_unique(std::__cxx11::string)’ is ambiguous"
Run Code Online (Sandbox Code Playgroud)

但是,如果我删除make_unique的本地定义,我也会收到错误:

"‘make_unique’ was not declared in this scope"
Run Code Online (Sandbox Code Playgroud)

看起来应该不可能得到这两个错误,因为std :: make_unique由于ADL而被拉入或者不是.这只是gcc的问题还是还有其他事情发生?

为了参考subbing make_unique为非模板std函数(如stoi)摆脱"未在此范围内声明"错误导致我相信它是gcc的问题.

#include <string>
#include <memory>

template <typename T, typename... Args>
inline std::unique_ptr<T> make_unique(Args&&... args)
{
    return std::unique_ptr<T>( new T(std::forward<Args>(args)...) );
}   

struct A
{
    A(std::string a){ }
};  

int main()
{
    auto a = make_unique<A>(std::string());
}   
Run Code Online (Sandbox Code Playgroud)

Jar*_*d42 4

这不是一个错误。

如果没有您的本地模板定义,

make_unique<A>(std::string());
Run Code Online (Sandbox Code Playgroud)

我们没有make_unique可用的模板定义,但我们有

(make_unique < A) > (std::string());
Run Code Online (Sandbox Code Playgroud)

根据您的定义,我们就有了模板定义,因此我们可以使用常规 ADL。