简体   繁体   English

可变参数模板元编程:clang ++或g ++中的错误?

[英]Variadic template metaprogramming : a bug in clang++ or g++?

Consider this variadic template madness to cast an array from one type to another: 考虑这种可变参数模板疯狂将数组从一种类型转换为另一种类型:

#include <array>
#include <type_traits>

template <typename Type>
class Converter
{
    public:
        template <typename OtherType, unsigned int OtherSize, class Array, typename... Types, class = typename std::enable_if<sizeof...(Types) != OtherSize>::type> 
        static constexpr const std::array<OtherType, OtherSize> convert(const Array source, const Types&... values);
        template <typename OtherType, unsigned int OtherSize, class Array, typename... Types, class = typename std::enable_if<sizeof...(Types) == OtherSize>::type> 
        static constexpr const std::array<OtherType, OtherSize> convert(const Array, const Types... values);
};

template <typename Type>
template <typename OtherType, unsigned int OtherSize, class Array, typename... Types, class> 
constexpr const std::array<OtherType, OtherSize> Converter<Type>::convert(const Array source, const Types&... values)
{
    return convert<OtherType, OtherSize>(source, values..., OtherType(source[sizeof...(values)]));
}

template <typename Type>
template <typename OtherType, unsigned int OtherSize, class Array, typename... Types, class> 
constexpr const std::array<OtherType, OtherSize> Converter<Type>::convert(const Array, const Types... values)
{
    return std::array<OtherType, OtherSize>({{values...}});
}

int main(int argc, char* argv[])
{
    Converter<double>::convert<int, 3>(std::array<double, 3>({{1., 2., 3.}}));
    return 0;
}

This code compiles well under g++4.7 and g++4.8 but not under clang++3.2 : 这段代码在g ++ 4.7和g ++ 4.8下编译得很好,但在clang ++ 3.2下却没有编译:

main.cpp:16:67: error: conflicting types for 'convert'
constexpr const std::array<OtherType, OtherSize> Converter<Type>::convert(const Array source, const Types&... values)
                                                                  ^
main.cpp:9:65: note: previous declaration is here
        static constexpr const std::array<OtherType, OtherSize> convert(const Array source, const Types&... values);
                                                                ^
main.cpp:23:67: error: conflicting types for 'convert'
constexpr const std::array<OtherType, OtherSize> Converter<Type>::convert(const Array, const Types... values)
                                                                  ^
main.cpp:11:65: note: previous declaration is here
        static constexpr const std::array<OtherType, OtherSize> convert(const Array, const Types... values);

Is g++ too permissive or is it a bug in clang++ (and if so, is there a public bugtracker of clang++) ? g ++是否过于宽松,或者它是clang ++中的错误(如果是这样,是否存在clang ++的公共错误跟踪器)?

是的,这就是已经在clang和修复中报告的这个bug

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 g ++和clang ++使用指向可变参数模板函数的指针的不同行为 - g++ and clang++ different behaviour with pointer to variadic template functions 使用lambdas的变量模板:使用g ++但使用clang ++运行时出错 - Variadic template using lambdas : error with g++ but running with clang++ 这是 g++ 或 clang++ 中的错误 - Is this a bug in g++ or clang++ 它是g ++和clang ++优化的错误吗? - Is it a bug for g++ and clang++ optimization? 模板元编程 - g ++吃它,clang没有 - template metaprogramming - g++ eats it, clang does not g ++和clang ++不同的行为推导可变参数模板`auto`值 - g++ and clang++ different behaviour deducing variadic template `auto` values 空包装的Functor可变参数模板包装扩展在clang ++和g ++中给出了不同的结果 - Functor variadic template pack expansion for empty pack gives different results in clang++ and g++ g++ 和 clang++ 与可变参数容器的不同行为 - g++ and clang++ different behaviour with variadic container 是否有g ++或clang ++调试选项来指导可变参数模板化 - Are there g++ or clang++ debug options to guide variadic templateing 使用递归可变参数模板bitset创建g ++和clang不同的行为(可能的gcc bug?) - g++ and clang different behavior with recursive variadic template bitset creation (possible gcc bug?)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM