片段:


#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.0MSVC-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

10-08 09:08