vendredi 25 août 2017

Variadic template partial specialisation "not more specialised" in g++ 7.1.1

I have an equivalent to std::integer_sequence (we're not using C++14 yet). I also have two helper classes that remove or add a leading number.

// Sequence type      
template <typename Type, Type ... Values>                                    
struct Sequence                                                              
{                                                                            
    using value_type = Type;                                                 
};                                                                           

// Pop a value off of the start of a sequence                                
template <class Class>                                                       
struct SequencePop;                                                          

template <typename Type, Type Value, Type ... Values>                        
struct SequencePop<Sequence<Type, Value, Values ...>>                        
{                                                                                                              
    using type = Sequence<Type, Values ...>;                                 
};                                                                           

// Push a value on to the start of a sequence                                
template <class Class, typename Class::value_type Value>                     
struct SequencePush;                                                         

template <typename Type, Type Value, Type ... Values>                        
struct SequencePush<Sequence<Type, Values ...>, Value>                       
{                                                                            
    using type = Sequence<Type, Value, Values ...>;                          
};                                                                           

SequencePop is considered valid in all compilers I have tried (g++ 6.4.1, g++ 7.1.1, clang++ 4.0.1). SequencePush doesn't compile with g++ 7.1.1. The error message is as follows.

test.cpp:24:8: error: partial specialization ‘struct SequencePush<Sequence<Type, Values ...>, Value>’ is not more specialized than [-fpermissive]
 struct SequencePush<Sequence<Type, Values ...>, Value>
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.cpp:21:8: note: primary template ‘template<class Class, typename Class::value_type Value> struct SequencePush’
 struct SequencePush;

Is g++ 7.1.1 correct to reject this code, and if so, how does one tell that SequencePush is not "more specialised" than the primary template?

Aucun commentaire:

Enregistrer un commentaire