Warm tip: This article is reproduced from serverfault.com, please click

其他-C ++ 17:在gcc中使用别名模板错误?

(其他 - C++ 17: Using alias template bug in gcc?)

发布于 2020-11-30 18:53:49

片段:


#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

Questioner
Juergen
Viewed
11
Juergen 2020-12-01 21:57:01

在此跟踪了该问题gcc-bugzilla