jeremyong/Selene

`make_unique` at include/selene/Registry.h:39

xicoh opened this issue · 5 comments

xicoh commented

I’m getting an ambiguity for the call to make_unique at line 39 of include/selene/Registry.h. The function is already defined in std:: but also in include/selene/util.h.

Try to use:

state["map"] = [](int x, int y){ return x * y; };

Building with clang 3.7 and -std=c++14.

The compiler complains that:

Selene/include/selene/Registry.h:39:13: error: call to 'make_unique' is ambiguous
            make_unique<Fun<arity, Ret, Args...>>(
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Selene/include/selene/Registry.h:32:9: note: in instantiation of function template specialization 'sel::Registry::Register<int, int, int>' requested here
        Register((typename detail::lambda_traits<L>::Fun)(lambda));
        ^
Selene/include/selene/Selector.h:198:24: note: in
  instantiation of function template specialization 'sel::Registry::Register<(lambda at script.cc:64:29)>' requested here
        _registry->Register(lambda);
                   ^
script.cc:64:27: note: in instantiation of function template specialization 'sel::Selector::operator=<(lambda at script.cc:64:29)>' requested here
  m_private->state["map"] = [](int x, int y){ return x * y; };
                          ^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/5.2.0/../../../../include/c++/5.2.0/bits/unique_ptr.h:764:5: note: candidate function [with _Tp = sel::Fun<1, int, int, int>, _Args = <lua_State *&, sel::MetatableRegistry &, std::function<int (int, int)> &>]
    make_unique(_Args&&... __args)
    ^
Selene/include/selene/util.h:94:20: note: candidate function [with T = sel::Fun<1, int, int, int>, Args = <lua_State *&, sel::MetatableRegistry &, std::function<int (int, int)> &>]
std::unique_ptr<T> make_unique(Args&&... args) {

Do you have using namespace std or similar in your cpp file?

xicoh commented

@AnonymousProgrammerLandau: No. The std version is available without a using thanks to argument dependent lookup, since the last argument is a std::function, as shown in the compiler message.

Oh, I overlooked the parameter std::function to the unqualified call to make_unique. That indeed pulls in the candidate from namespace std.

Does explicitly qualifying the call sel::make_unique solve your problem?

@jeremyong I think expanding the build matrix on Travis to C++14 might be a good idea.

xicoh commented

Yes, qualifying the call solves the problem, with either sel:: or std::.

This should be fixed now, but I believe some of the sel variants of functions like make_unique are no longer needed now that all major compilers support it. Closing for now.