[英]Variadic template doesn't recognise a constexpr function
我正在尝试在编译时初始化一些C ++数组,但出现了奇怪的g ++错误。 这是我能够获得的最小代码段,可重现错误:
#include <array>
template<typename Ar, int... Vals>
constexpr Ar Map(typename Ar::value_type /*int*/ fun(int))
{ return {{ fun(Vals)... }}; }
constexpr int add(int i) { return i + 1; }
constexpr auto b = Map<std::array<int, 2>, 1, 2>(add);
编译器在抱怨
bug.cpp:8:53: in constexpr expansion of ‘Map<std::array<int, 2ul>, {1, 2}>(add)’
bug.cpp:4:80: error: expression ‘add’ does not designate a constexpr function
constexpr Ar Map(typename Ar::value_type /*int*/ fun(int)) { return {{ fun(Vals)... }}; }
g ++ 4.7.1和4.9.0 20130520(实验性)均会发生这种情况。 请注意,如果我在Map
的定义中用int
替换typename Ar::value_type
(请参见注释),则一切都会按预期进行。 这是我做错事了吗?
我认为这是Bug 52892-函数指针失去constexpr限定 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.