片段:
#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;
}
可以使用clang-12.0.0
和编译良好MSVC-19.16.27034
,但gcc-11.0.0
会引发错误:
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;
|
谁是对的,谁不是?
编辑: 在这里跟踪错误gcc-bugzilla
在此跟踪了该问题gcc-bugzilla
我不这么认为。乔纳森(Jonathan)只是简化了例子,尚未得到官方确认。
@cigien:我的坏。我不知道bugzilla中的语义。将进行防御性编辑。
不用担心。感谢您提交错误报告。在我看来,这确实像个虫子,这是值得的:)