p5.cpp revision 8491ffe86c50241b47c6d7ef8cd9ee00f5e675da
1// RUN: %clang_cc1 -std=c++0x -fblocks -fsyntax-only -verify %s 2 3template<typename T, typename U> struct pair; 4template<typename ...> struct tuple; 5 6// A parameter pack whose name appears within the pattern of a pack 7// expansion is expanded by that pack expansion. An appearance of the 8// name of a parameter pack is only expanded by the innermost 9// enclosing pack expansion. The pattern of a pack expansion shall 10// name one or more parameter packs that are not expanded by a nested 11// pack expansion. 12template<typename... Types> 13struct Expansion { 14 typedef pair<Types..., int> expand_with_pacs; // okay 15 typedef pair<Types, int...> expand_no_packs; // expected-error{{pack expansion does not contain any unexpanded parameter packs}} 16 typedef pair<pair<Types..., int>..., int> expand_with_expanded_nested; // expected-error{{pack expansion does not contain any unexpanded parameter packs}} 17}; 18 19// All of the parameter packs expanded by a pack expansion shall have 20// the same number of arguments specified. 21template<typename ...Types> 22struct ExpansionLengthMismatch { 23 template<typename ...OtherTypes> 24 struct Inner { 25 typedef tuple<pair<Types, OtherTypes>...> type; // expected-error{{pack expansion contains parameter packs 'Types' and 'OtherTypes' that have different lengths (3 vs. 2)}} 26 }; 27}; 28 29ExpansionLengthMismatch<int, long>::Inner<unsigned int, unsigned long>::type 30 *il_pairs; 31tuple<pair<int, unsigned int>, pair<long, unsigned long> >*il_pairs_2 = il_pairs; 32 33ExpansionLengthMismatch<short, int, long>::Inner<unsigned int, unsigned long>::type // expected-note{{in instantiation of}} 34 *il_pairs_bad; 35 36 37// An appearance of a name of a parameter pack that is not expanded is 38// ill-formed. 39 40// Test for unexpanded parameter packs in each of the type nodes. 41template<typename T, int N, typename ... Types> 42struct TestPPName 43 : public Types, public T // expected-error{{base type contains unexpanded parameter pack 'Types'}} 44{ 45 // BuiltinType is uninteresting 46 // FIXME: ComplexType is uninteresting? 47 // PointerType 48 typedef Types *types_pointer; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 49 50 // BlockPointerType 51 typedef Types (^block_pointer_1)(int); // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 52 typedef int (^block_pointer_2)(Types); // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 53 54 // LValueReferenceType 55 typedef Types &lvalue_ref; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 56 57 // RValueReferenceType 58 typedef Types &&rvalue_ref; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 59 60 // MemberPointerType 61 typedef Types TestPPName::* member_pointer_1; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 62 typedef int Types::*member_pointer_2; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 63 64 // ConstantArrayType 65 typedef Types constant_array[17]; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 66 67 // IncompleteArrayType 68 typedef Types incomplete_array[]; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 69 70 // VariableArrayType 71 void f(int i) { 72 Types variable_array[i]; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 73 } 74 75 // DependentSizedArrayType 76 typedef Types dependent_sized_array[N]; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 77 78 // DependentSizedExtVectorType 79 typedef Types dependent_sized_ext_vector __attribute__((ext_vector_type(N))); // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 80 81 // VectorType is uninteresting 82 83 // ExtVectorType 84 typedef Types ext_vector __attribute__((ext_vector_type(4))); // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 85 86 // FunctionProtoType 87 typedef Types (function_type_1)(int); // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 88 typedef int (function_type_2)(Types); // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 89 90 // FunctionNoProtoType is uninteresting 91 // UnresolvedUsingType is uninteresting 92 // ParenType is uninteresting 93 // TypedefType is uninteresting 94 95 // TypeOfExprType 96 typedef __typeof__((static_cast<Types>(0))) typeof_expr; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 97 98 // TypeOfType 99 typedef __typeof__(Types) typeof_type; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 100 101 // DecltypeType 102 typedef decltype((static_cast<Types>(0))) typeof_expr; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 103 104 // RecordType is uninteresting 105 // EnumType is uninteresting 106 // ElaboratedType is uninteresting 107 108 // TemplateTypeParmType 109 typedef Types template_type_parm; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 110 111 // SubstTemplateTypeParmType is uninteresting 112 113 // TemplateSpecializationType 114 typedef pair<Types, int> template_specialization; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 115 116 // InjectedClassName is uninteresting. 117 118 // DependentNameType 119 typedef typename Types::type dependent_name; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 120 121 // DependentTemplateSpecializationType 122 typedef typename Types::template apply<int> dependent_name_1; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 123 typedef typename T::template apply<Types> dependent_name_2; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 124 125 // ObjCObjectType is uninteresting 126 // ObjCInterfaceType is uninteresting 127 // ObjCObjectPointerType is uninteresting 128}; 129 130// FIXME: Test for unexpanded parameter packs in each of the expression nodes. 131 132template<typename ... Types> 133void TestPPNameFunc(int i) { 134 f(static_cast<Types>(i)); // expected-error{{expression contains unexpanded parameter pack 'Types'}} 135} 136 137// Test for unexpanded parameter packs in declarations. 138// FIXME: Attributes? 139template<typename T, typename... Types> 140struct TestUnexpandedDecls : T{ 141 void member_function(Types); // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 142 void member_function () throw(Types); // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 143 operator Types() const; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 144 Types data_member; // expected-error{{data member type contains unexpanded parameter pack 'Types'}} 145 static Types static_data_member; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 146 unsigned bit_field : static_cast<Types>(0); // expected-error{{bit-field size contains unexpanded parameter pack 'Types'}} 147 static_assert(static_cast<Types>(0), "Boom"); // expected-error{{static assertion contains unexpanded parameter pack 'Types'}} 148 149 enum E0 : Types { // expected-error{{fixed underlying type contains unexpanded parameter pack 'Types'}} 150 EnumValue = static_cast<Types>(0) // expected-error{{enumerator value contains unexpanded parameter pack 'Types'}} 151 }; 152 153 using typename Types::type; // expected-error{{using declaration contains unexpanded parameter pack 'Types'}} 154 using Types::value; // expected-error{{using declaration contains unexpanded parameter pack 'Types'}} 155 using T::operator Types; // expected-error{{using declaration contains unexpanded parameter pack 'Types'}} 156 157 friend class Types::foo; // expected-error{{friend declaration contains unexpanded parameter pack 'Types'}} 158 friend void friend_func(Types); // expected-error{{friend declaration contains unexpanded parameter pack 'Types'}} 159 friend void Types::other_friend_func(int); // expected-error{{friend declaration contains unexpanded parameter pack 'Types'}} 160 161 void test_initializers() { 162 T copy_init = static_cast<Types>(0); // expected-error{{initializer contains unexpanded parameter pack 'Types'}} 163 T direct_init(0, static_cast<Types>(0)); // expected-error{{expression contains unexpanded parameter pack 'Types'}} 164 T list_init = { static_cast<Types>(0) }; // expected-error{{initializer contains unexpanded parameter pack 'Types'}} 165 } 166 167 void default_function_args(T = static_cast<Types>(0)); // expected-error{{default argument contains unexpanded parameter pack 'Types'}} 168 169 template<typename = Types*> // expected-error{{default argument contains unexpanded parameter pack 'Types'}} 170 struct default_template_args_1; 171 template<int = static_cast<Types>(0)> // expected-error{{default argument contains unexpanded parameter pack 'Types'}} 172 struct default_template_args_2; 173 template<template<typename> class = Types::template apply> // expected-error{{default argument contains unexpanded parameter pack 'Types'}} 174 struct default_template_args_3; 175 176 template<Types value> // expected-error{{non-type template parameter type contains unexpanded parameter pack 'Types'}} 177 struct non_type_template_param_type; 178 179 void decls_in_stmts() { 180 Types t; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 181 for (Types *t = 0; ; ) { } // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 182 for (; Types *t = 0; ) { } // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 183 switch(Types *t = 0) { } // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 184 while(Types *t = 0) { } // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 185 if (Types *t = 0) { } // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 186 try { 187 } catch (Types*) { // expected-error{{exception type contains unexpanded parameter pack 'Types'}} 188 } 189 } 190}; 191 192// FIXME: Test for unexpanded parameter packs in each of the statements. 193 194// FIXME: Once we have template argument deduction, we can test 195// unexpanded parameter packs in partial specializations. 196// template<typename ...Types> 197// struct TestUnexpandedDecls<int, Types>; 198 199// Test for diagnostics in the presence of multiple unexpanded 200// parameter packs. 201template<typename T, typename U> struct pair; 202 203template<typename ...OuterTypes> 204struct MemberTemplatePPNames { 205 template<typename ...InnerTypes> 206 struct Inner { 207 typedef pair<OuterTypes, InnerTypes>* types; // expected-error{{declaration type contains unexpanded parameter packs 'OuterTypes' and 'InnerTypes'}} 208 209 template<typename ...VeryInnerTypes> 210 struct VeryInner { 211 typedef pair<pair<VeryInnerTypes, OuterTypes>, pair<InnerTypes, OuterTypes> > types; // expected-error{{declaration type contains unexpanded parameter packs 'VeryInnerTypes', 'OuterTypes', ...}} 212 }; 213 }; 214}; 215 216