Reputation: 14987
I'm trying to customize std::function
and beginning with the following code:
#include <functional>
template <typename>
struct my_function;
template <typename R, typename... Args>
struct my_function<R(Args...)> : std::function<R(Args...)> {
using base = std::function<R(Args...)>;
using base::function;
};
int main() {
my_function<int(int)> f = nullptr;
}
I'm expecting that the constructor from std::function
that takes an std::nullptr_t
object is inherited by my_function
. So, the code should compile fine. While GCC 5.2 (C++14) has no problem in compiling the code, clang 3.6 (C++14) produced the following error message which is quite confusing:
n file included from main.cpp:1:
/usr/include/c++/v1/functional:1454:41: error: no type named 'type' in 'std::__1::enable_if<false, void>'; 'enable_if' cannot be used to disable this declaration
__callable<_Fp>::value &&
^~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:10:15: note: in instantiation of member function 'std::__1::function<int (int)>::function' requested here
using base::function;
^
main.cpp:14:25: note: while substituting deduced template arguments into function template 'my_function' [with _Fp = nullptr_t]
my_function<int(int)> f = nullptr;
^
1 error generated.
Is this a clang bug or my code is just incorrect? If (very fortunately) the latter is true, how should I fix the code?
Upvotes: 3
Views: 413