Snippet:
#include <functional>
template <typename T>
struct CallableTrait;
template <typename R, typename... Args>
struct CallableTrait<std::function<R(Args...)>>
{
using ReturnType = R;
};
template <typename Callable>
using CallableTraitT = CallableTrait<decltype(std::function{std::declval<Callable>()})>;
template <typename Callable>
auto test(Callable&&)
{
using CallableInfo = CallableTraitT<Callable>;
static_assert(!std::is_void_v<typename CallableInfo::ReturnType>);
}
int main()
{
test([]() { return 42; });
return 0;
}
This compiles fine with clang-12.0.0
and MSVC-19.16.27034
, but gcc-11.0.0
throws an error:
prog.cc: In instantiation of 'auto test(Callable&&) [with Callable = main()::<lambda()>]':
prog.cc:25:29: required from here
prog.cc:20:25: error: invalid use of incomplete type 'struct CallableTrait<main()::<lambda()> >'
20 | static_assert(!std::is_void_v<typename CallableInfo::ReturnType>);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.cc:5:8: note: declaration of 'struct CallableTrait<main()::<lambda()> >'
5 | struct CallableTrait;
|
Who is right and who isn't?
EDIT: Bug is tracked here gcc-bugzilla
[]() { return 42; }
≠std::function<int()>
.CallableTraitT
"calls"std::function
...std::function
makes gcc happy Demo.