Anonymous temporary arguments and class template template argument - gcc vs clang

Consider the following code snippet:

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

int main()
{
    foo{0};
}

g ++ 7 happily creates a temporary type object foo, inferring T = int.

clang ++ 5 and 6 refuse to compile code:

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

live example in wandbox


Is this a clang error or is there something in the standard that prevents the template template argument from being subtracted for unnamed time series?

+6
source share
1 answer

Clang Error ( # 34091 )

From [dcl.type.class.deduct] :

[...] explicit ( ). . [:

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

- ]

+6

All Articles