6

対GCCは、次のコードスニペットを考えてみましょう:++ 7匿名一時とクラステンプレート引数控除 - 打ち鳴らす

template <typename T> 
struct foo 
{ 
    foo(T) { } 
}; 

int main() 
{ 
    foo{0}; 
} 

グラムは喜んでT = intを推測、タイプfooの一時オブジェクトを作成します。

error: expected unqualified-id 
    foo{0}; 
    ^

live example on wandbox


この打ち鳴らすのバグですか、そこには、その防止標準で何かです:

打ち鳴らす++ 5及び6は、コードをコンパイルすることを拒否するクラステンプレート引数の控除名前の付けられていないtemporari es?

答えて

6

[dcl.type.class.deduct]からクランバグ(#34091

推定クラスタイプのプレースホルダでも使用することができる[...] または単純型指定子としてexplicit type conversion (functional notation)にあります。推論されたクラス型のプレースホルダは、他のコンテキストには現れてはならない。 [例:

template<class T> struct container { 
    container(T t) {} 
    template<class Iter> container(Iter beg, Iter end); 
}; 

template<class Iter> 
container(Iter b, Iter e) -> container<typename std::iterator_traits<Iter>::value_type>; 
std::vector<double> v = { /* ... */ }; 

container c(7);       // OK, deduces int for T 
auto d = container(v.begin(), v.end()); // OK, deduces double for T 
container e{5, 6};      // error, int is not an iterator 

- 終了例]

関連する問題