2017-08-10 21 views
0

私はGCC 5.4(online example)と、以下のC++ 14のコードにコンパイルしようとしています:GCC5:ネストされた変数テンプレートは関数テンプレートではありませんか?

template<typename T> 
struct traits { 
    template<typename X> 
    static constexpr bool vect = true; 
}; 

template<typename T1, typename T2> 
constexpr bool all_vect = traits<T1>::template vect<T2>; 

bool something() { 
    return all_vect<void, double>; 
} 

をしかし、私は次のエラーだ:私はGCCには問題がありませんが

<source>: In instantiation of 'constexpr const bool all_vect<void, double>': 
<source>:11:12: required from here 
<source>:8:16: error: 'template<class X> constexpr const bool traits<void>::vect<X>' is not a function template 
constexpr bool all_vect = traits<T1>::template vect<T2>; 
       ^
<source>:8:16: error: 'vect<T2>' is not a member of 'traits<void>' 
Compiler exited with result code 1 

を6.1以上、または3.9以上である。しかし、それは私が試したGCC5のすべてのバージョンで同じです。

この理由が見つかりませんか?通常、GCC5はC++ 14の機能が完了している必要があります。

変数テンプレートを使用しているGCC5では、この問題の簡単な回避策がありますか?私は、すべての私の形質を可変テンプレートを使用するように変換しているので、単純な形質を使用することに戻っていません。

答えて

1

これは、dupeに示されているように、gcc6で修正されたバグです。

テンプレート変数を保持しているときの回避策はないようです。

template<typename T> 
struct traits { 

    template<typename X> 
    struct Is_vect 
    { 
     static constexpr bool value = true; 
    }; 
}; 

template<typename T1, typename T2> 
struct Are_all_vect 
{ 
    static constexpr bool value = traits<T1>::template Is_vect<T2>::value; 
}; 


bool something() { 
    return Are_all_vect<void, double>::value; 
} 

またはテンプレートconstexprの機能::答えを

template<typename T> 
struct traits { 
    template<typename X> 
    static constexpr bool vect() { return true; } 
}; 

template<typename T1, typename T2> 
constexpr bool all_vect() { return traits<T1>::template vect<T2>(); } 

bool something() { 
    return all_vect<void, double>(); 
} 
+0

おかげで離れてあなたが古き良き静的非テンプレート変数を使用することができ、可変テンプレートからshies回避策については

。私は実際に変数テンプレートを使用してより簡単な回避策を探していました。私は、すべての私の形質を可変テンプレートを使用するように変換しているので、単純な形質を使用することに戻っていません。 –

+1

@Baptisteあなたの唯一の選択肢は、バグを修正した古いバージョンのコンパイラか、古いバージョンに戻すか、またはconstexpr関数を持つことができるようです。 – bolov

関連する問題