1762bb9d0ad20320b9f97a841dce57ba5e8e48b07Richard Smith// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s 2ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 3ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor// Test parsing + semantic analysis 4ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregortemplate<typename ...Types> struct count_types { 5ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor static const unsigned value = sizeof...(Types); 6ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor}; 7ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 8ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregortemplate<int ...Values> struct count_ints { 9ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor static const unsigned value = sizeof...(Values); 10ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor}; 11ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 12ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor// Test instantiation 13ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregorint check_types[count_types<short, int, long>::value == 3? 1 : -1]; 14ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregorint check_ints[count_ints<1, 2, 3, 4, 5>::value == 5? 1 : -1]; 15ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 1612c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor// Test instantiation involving function parameter packs. 1712c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregorstruct any { 1812c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor template<typename T> any(T); 1912c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor}; 2012c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor 2112c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregortemplate<typename ...Inits> 2212c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregorvoid init_me(Inits ...inits) { 2312c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor any array[sizeof...(inits)] = { inits... }; 2412c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor} 2512c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor 2612c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregortemplate void init_me<int, float, double*>(int, float, double*); 2712c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor 28ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor// Test parser and semantic recovery. 29ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregortemplate<int Value> struct count_ints_2 { 30ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor static const unsigned value = sizeof...(Value); // expected-error{{'Value' does not refer to the name of a parameter pack}} 31ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor}; 32ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 33ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregortemplate<typename ...Types> // expected-note{{parameter pack 'Types' declared here}} 34ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregorstruct count_types_2 { 35ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor static const unsigned value = sizeof... Type; // expected-error{{missing parentheses around the size of parameter pack 'Type'}} \ 36ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // expected-error{{Type' does not refer to the name of a parameter pack; did you mean 'Types'?}} 37ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor}; 38ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 39