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

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

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

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;
}

Demo

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

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

The issue is tracked here gcc-bugzilla