13

g ++(バージョン4.8.1_1、Macports)とclang ++(バージョン3.3、Macports)用のTMP-heavyコードをいくつか書いています。 g ++はUNBRIDLED FURYのコードリストを拒否しますが、clang ++は猶予華麗でコンパイルします。g ++部分テンプレートの特殊化によるバグ

  • 右側にはどのコンパイラがありますか? (私はそれがg ++だと強く思っていますが、バグレポートを提出する前に他人から安心して欲しいと思います)
  • 提案する簡単な、あるいはエレガントな回避策がありますか? (私はそうグラム++コードを受け入れることを引き起こす、構造体への切り替え、オプションではありません、テンプレートの別名を使用する必要があります。)

ここでのコードリストは、ちょうどあなたのためを作りました。ここで

template <class... Ts> 
struct sequence; 

template <int T> 
struct integer; 

// This definition of `extents` causes g++ to issue a compile-time error. 
template <int... Ts> 
using extents = sequence<integer<Ts>...>; 

// However, this definition works without any problems. 
// template <int... Ts> 
// struct extents; 

template <int A, int B, class Current> 
struct foo; 

template <int A, int B, int... Ts> 
struct foo<A, B, extents<Ts...>> 
{ 
    using type = int; 
}; 

template <int B, int... Ts> 
struct foo<B, B, extents<Ts...>> 
{ 
    using type = int; 
}; 

int main() 
{ 
    using t = foo<1, 1, extents<>>::type; 
    return 0; 
} 

がg ++の出力:ここ

er.cpp: In function 'int main()': 
er.cpp:39:41: error: ambiguous class template instantiation for 'struct foo<1, 1, sequence<> >' 
    using t = typename foo<1, 1, extents<>>::type; 
             ^
er.cpp:26:8: error: candidates are: struct foo<A, B, sequence<integer<Ts>...> > 
struct foo<A, B, extents<Ts...>> 
     ^
er.cpp:32:8: error:     struct foo<B, B, sequence<integer<Ts>...> > 
struct foo<B, B, extents<Ts...>> 
     ^
er.cpp:39:43: error: 'type' in 'struct foo<1, 1, sequence<> >' does not name a type 
    using t = typename foo<1, 1, extents<>>::type; 
             ^

が打ち鳴らす++ 'であるの出力は:あなたの助けのための

ありがとう!

+4

ジョークだけでも「+ 1」:)私はまた、ここではクランが正しいと確信しています。 –

+0

'main'の' typename'は不要です –

+0

@DavidRodríguez-dribeasありがとう、それは習慣になっています... –

答えて

関連する問題