Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/145.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;17:在gcc中使用别名模板错误?_C++_Templates_C++17_Language Lawyer - Fatal编程技术网

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

C++ C++;17:在gcc中使用别名模板错误?,c++,templates,c++17,language-lawyer,C++,Templates,C++17,Language Lawyer,片段: #include <functional> template <typename T> struct CallableTrait; template <typename R, typename... Args> struct CallableTrait<std::function<R(Args...)>> { using ReturnType = R; }; template <typename Calla

片段:


#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;
}
谁对谁错

编辑:
错误在此处跟踪

问题在此处跟踪

[](){return 42;}
std::function
。你想要的基本上就是我在这里所做的:@NathanOliver:Thx,但问题是为什么三个编译器中有两个是好的,而gcc认为这是错误的。@Eljay:但是
CallableTraitT
“调用”
std::function
…事实上,添加
std::function
会让gcc高兴。我不这么认为。乔纳森只是简化了这个例子,还没有正式确认。@cigien:我的错。我不知道bugzilla中的语义。将进行防御性编辑。不用担心。谢谢你提交错误报告。对我来说,它确实像一只虫子,值得一提的是:)
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;
      |