gpt4 book ai didi

C++ 17 : Using alias template bug in gcc?

转载 作者:行者123 更新时间:2023-12-03 10:06:14 25 4
gpt4 key购买 nike

片段:


#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;
}
Demo
这与 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

关于C++ 17 : Using alias template bug in gcc?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65079471/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com