p5.cpp revision 10738d36b150aa65206890c1c845cdba076e4200
17dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// RUN: %clang_cc1 -std=c++0x -fblocks -fsyntax-only -verify %s 27dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 37dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochtemplate<typename T, typename U> struct pair; 47dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochtemplate<typename ...> struct tuple; 57dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 67dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// A parameter pack whose name appears within the pattern of a pack 77dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// expansion is expanded by that pack expansion. An appearance of the 87dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// name of a parameter pack is only expanded by the innermost 97dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// enclosing pack expansion. The pattern of a pack expansion shall 107dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// name one or more parameter packs that are not expanded by a nested 117dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// pack expansion. 127dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochtemplate<typename... Types> 137dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochstruct Expansion { 147dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch typedef pair<Types..., int> expand_with_pacs; // okay 157dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch typedef pair<Types, int...> expand_no_packs; // expected-error{{pack expansion does not contain any unexpanded parameter packs}} 167dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch typedef pair<pair<Types..., int>..., int> expand_with_expanded_nested; // expected-error{{pack expansion does not contain any unexpanded parameter packs}} 177dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}; 187dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 197dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// All of the parameter packs expanded by a pack expansion shall have 207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// the same number of arguments specified. 217dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochtemplate<typename ...Types> 227dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochstruct ExpansionLengthMismatch { 237dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch template<typename ...OtherTypes> 247dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch struct Inner { 257dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch typedef tuple<pair<Types, OtherTypes>...> type; // expected-error{{pack expansion contains parameter packs 'Types' and 'OtherTypes' that have different lengths (3 vs. 2)}} 267dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch }; 277dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}; 287dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 297dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochExpansionLengthMismatch<int, long>::Inner<unsigned int, unsigned long>::type 307dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch *il_pairs; 317dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochtuple<pair<int, unsigned int>, pair<long, unsigned long> >*il_pairs_2 = il_pairs; 327dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 337dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochExpansionLengthMismatch<short, int, long>::Inner<unsigned int, unsigned long>::type // expected-note{{in instantiation of template class 'ExpansionLengthMismatch<short, int, long>::Inner<unsigned int, unsigned long>' requested here}} 347dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch *il_pairs_bad; 357dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 367dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// An appearance of a name of a parameter pack that is not expanded is 387dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// ill-formed. 397dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 407dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// Test for unexpanded parameter packs in each of the type nodes. 417dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochtemplate<typename T, int N, typename ... Types> 427dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochstruct TestPPName 437dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch : public Types, public T // expected-error{{base type contains unexpanded parameter pack 'Types'}} 447dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch{ 457dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // BuiltinType is uninteresting 467dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // FIXME: ComplexType is uninteresting? 477dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // PointerType 487dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch typedef Types *types_pointer; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 497dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 507dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // BlockPointerType 517dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch typedef Types (^block_pointer_1)(int); // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 527dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch typedef int (^block_pointer_2)(Types); // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 537dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 547dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // LValueReferenceType 557dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch typedef Types &lvalue_ref; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 567dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 577dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // RValueReferenceType 587dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch typedef Types &&rvalue_ref; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 597dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 607dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // MemberPointerType 617dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch typedef Types TestPPName::* member_pointer_1; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 627dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch typedef int Types::*member_pointer_2; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 637dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 647dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // ConstantArrayType 657dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch typedef Types constant_array[17]; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 667dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 677dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // IncompleteArrayType 687dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch typedef Types incomplete_array[]; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 697dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 707dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // VariableArrayType 717dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch void f(int i) { 727dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch Types variable_array[i]; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 737dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch } 747dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 757dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // DependentSizedArrayType 767dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch typedef Types dependent_sized_array[N]; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 777dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 787dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // DependentSizedExtVectorType 797dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch typedef Types dependent_sized_ext_vector __attribute__((ext_vector_type(N))); // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 807dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 817dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // VectorType is uninteresting 827dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 837dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // ExtVectorType 847dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch typedef Types ext_vector __attribute__((ext_vector_type(4))); // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 857dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 867dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // FunctionProtoType 877dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch typedef Types (function_type_1)(int); // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 887dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch typedef int (function_type_2)(Types); // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 897dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 907dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // FunctionNoProtoType is uninteresting 917dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // UnresolvedUsingType is uninteresting 927dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // ParenType is uninteresting 937dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // TypedefType is uninteresting 947dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 957dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // TypeOfExprType 967dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch typedef __typeof__((static_cast<Types>(0))) typeof_expr; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 977dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 987dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // TypeOfType 997dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch typedef __typeof__(Types) typeof_type; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 1007dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 1017dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // DecltypeType 1027dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch typedef decltype((static_cast<Types>(0))) typeof_expr; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 1037dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 1047dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // RecordType is uninteresting 1057dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // EnumType is uninteresting 1067dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // ElaboratedType is uninteresting 1077dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 1087dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // TemplateTypeParmType 1097dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch typedef Types template_type_parm; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 1107dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 1117dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // SubstTemplateTypeParmType is uninteresting 1127dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 1137dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // TemplateSpecializationType 1147dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch typedef pair<Types, int> template_specialization; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 1157dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 1167dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // InjectedClassName is uninteresting. 1177dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 1187dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // DependentNameType 1197dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch typedef typename Types::type dependent_name; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 1207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 1217dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // DependentTemplateSpecializationType 1227dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch typedef typename Types::template apply<int> dependent_name_1; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 1237dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch typedef typename T::template apply<Types> dependent_name_2; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 1247dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 1257dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // ObjCObjectType is uninteresting 1267dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // ObjCInterfaceType is uninteresting 1277dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // ObjCObjectPointerType is uninteresting 1287dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}; 1297dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 130// FIXME: Test for unexpanded parameter packs in each of the expression nodes. 131template<int ...Values> 132void test_unexpanded_in_exprs() { 133 // PredefinedExpr is uninteresting 134 // DeclRefExpr 135 Values; // expected-error{{expression contains unexpanded parameter pack 'Values'}} 136 // IntegerLiteral is uninteresting 137 // FloatingLiteral is uninteresting 138 // ImaginaryLiteral is uninteresting 139 // StringLiteral is uninteresting 140 // CharacterLiteral is uninteresting 141 (Values); // expected-error{{expression contains unexpanded parameter pack 'Values'}} 142 // UnaryOperator 143 -Values; // expected-error{{expression contains unexpanded parameter pack 'Values'}} 144 // OffsetOfExpr 145 struct OffsetMe { 146 int array[17]; 147 }; 148 __builtin_offsetof(OffsetMe, array[Values]); // expected-error{{expression contains unexpanded parameter pack 'Values'}} 149 // FIXME: continue this... 150} 151 152template<typename ... Types> 153void TestPPNameFunc(int i) { 154 f(static_cast<Types>(i)); // expected-error{{expression contains unexpanded parameter pack 'Types'}} 155} 156 157// Test for unexpanded parameter packs in declarations. 158// FIXME: Attributes? 159template<typename T, typename... Types> 160struct TestUnexpandedDecls : T{ 161 void member_function(Types); // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 162 void member_function () throw(Types); // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 163 operator Types() const; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 164 Types data_member; // expected-error{{data member type contains unexpanded parameter pack 'Types'}} 165 static Types static_data_member; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 166 unsigned bit_field : static_cast<Types>(0); // expected-error{{bit-field size contains unexpanded parameter pack 'Types'}} 167 static_assert(static_cast<Types>(0), "Boom"); // expected-error{{static assertion contains unexpanded parameter pack 'Types'}} 168 169 enum E0 : Types { // expected-error{{fixed underlying type contains unexpanded parameter pack 'Types'}} 170 EnumValue = static_cast<Types>(0) // expected-error{{enumerator value contains unexpanded parameter pack 'Types'}} 171 }; 172 173 using typename Types::type; // expected-error{{using declaration contains unexpanded parameter pack 'Types'}} 174 using Types::value; // expected-error{{using declaration contains unexpanded parameter pack 'Types'}} 175 using T::operator Types; // expected-error{{using declaration contains unexpanded parameter pack 'Types'}} 176 177 friend class Types::foo; // expected-error{{friend declaration contains unexpanded parameter pack 'Types'}} 178 friend void friend_func(Types); // expected-error{{friend declaration contains unexpanded parameter pack 'Types'}} 179 friend void Types::other_friend_func(int); // expected-error{{friend declaration contains unexpanded parameter pack 'Types'}} 180 181 void test_initializers() { 182 T copy_init = static_cast<Types>(0); // expected-error{{initializer contains unexpanded parameter pack 'Types'}} 183 T direct_init(0, static_cast<Types>(0)); // expected-error{{expression contains unexpanded parameter pack 'Types'}} 184 T list_init = { static_cast<Types>(0) }; // expected-error{{initializer contains unexpanded parameter pack 'Types'}} 185 } 186 187 void default_function_args(T = static_cast<Types>(0)); // expected-error{{default argument contains unexpanded parameter pack 'Types'}} 188 189 template<typename = Types*> // expected-error{{default argument contains unexpanded parameter pack 'Types'}} 190 struct default_template_args_1; 191 template<int = static_cast<Types>(0)> // expected-error{{default argument contains unexpanded parameter pack 'Types'}} 192 struct default_template_args_2; 193 template<template<typename> class = Types::template apply> // expected-error{{default argument contains unexpanded parameter pack 'Types'}} 194 struct default_template_args_3; 195 196 template<Types value> // expected-error{{non-type template parameter type contains unexpanded parameter pack 'Types'}} 197 struct non_type_template_param_type; 198 199 void decls_in_stmts() { 200 Types t; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 201 for (Types *t = 0; ; ) { } // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 202 for (; Types *t = 0; ) { } // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 203 switch(Types *t = 0) { } // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 204 while(Types *t = 0) { } // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 205 if (Types *t = 0) { } // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} 206 try { 207 } catch (Types*) { // expected-error{{exception type contains unexpanded parameter pack 'Types'}} 208 } 209 } 210}; 211 212// FIXME: Test for unexpanded parameter packs in each of the statements. 213 214// FIXME: Once we have template argument deduction, we can test 215// unexpanded parameter packs in partial specializations. 216// template<typename ...Types> 217// struct TestUnexpandedDecls<int, Types>; 218 219// Test for diagnostics in the presence of multiple unexpanded 220// parameter packs. 221template<typename T, typename U> struct pair; 222 223template<typename ...OuterTypes> 224struct MemberTemplatePPNames { 225 template<typename ...InnerTypes> 226 struct Inner { 227 typedef pair<OuterTypes, InnerTypes>* types; // expected-error{{declaration type contains unexpanded parameter packs 'OuterTypes' and 'InnerTypes'}} 228 229 template<typename ...VeryInnerTypes> 230 struct VeryInner { 231 typedef pair<pair<VeryInnerTypes, OuterTypes>, pair<InnerTypes, OuterTypes> > types; // expected-error{{declaration type contains unexpanded parameter packs 'VeryInnerTypes', 'OuterTypes', ...}} 232 }; 233 }; 234}; 235 236