p5.cpp revision a31040f16604849b3b1dc36015056c81bae68ad1
1cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor// RUN: %clang_cc1 -std=c++0x -fblocks -fsyntax-only -verify %s
2d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
3d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
4d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor// An appearance of a name of a parameter pack that is not expanded is
5d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor// ill-formed.
6cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
7cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregortemplate<typename T, typename U> struct pair;
8cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
9cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor// Test for unexpanded parameter packs in each of the type nodes.
10cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregortemplate<typename T, int N, typename ... Types>
11d0937224f383c7cc72c947119380f9713a070c73Douglas Gregorstruct TestPPName
12cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  : public Types, public T  // expected-error{{base type contains unexpanded parameter pack 'Types'}}
13d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{
14cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // BuiltinType is uninteresting
15cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // FIXME: ComplexType is uninteresting?
16cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // PointerType
179ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor  typedef Types *types_pointer; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
18cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
19cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // BlockPointerType
20cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  typedef Types (^block_pointer_1)(int); // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
21cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  typedef int (^block_pointer_2)(Types); // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
22cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
23cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // LValueReferenceType
24cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  typedef Types &lvalue_ref; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
25cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
26cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // RValueReferenceType
27cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  typedef Types &&rvalue_ref; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
28cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
29cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // MemberPointerType
30cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  typedef Types TestPPName::* member_pointer_1; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
31cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  typedef int Types::*member_pointer_2; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
32cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
33cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // ConstantArrayType
34cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  typedef Types constant_array[17]; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
35cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
36cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // IncompleteArrayType
37cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  typedef Types incomplete_array[]; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
38cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
39cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // VariableArrayType
40cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  void f(int i) {
41cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor    Types variable_array[i]; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
42cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  }
43cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
44cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // DependentSizedArrayType
45cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  typedef Types dependent_sized_array[N]; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
46cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
47cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // DependentSizedExtVectorType
48cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  typedef Types dependent_sized_ext_vector __attribute__((ext_vector_type(N))); // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
49cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
50cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // VectorType is uninteresting
51cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
52cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // ExtVectorType
53cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  typedef Types ext_vector __attribute__((ext_vector_type(4))); // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
54cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
55cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // FunctionProtoType
56cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  typedef Types (function_type_1)(int); // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
57cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  typedef int (function_type_2)(Types); // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
58cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
59cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // FunctionNoProtoType is uninteresting
60cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // UnresolvedUsingType is uninteresting
61cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // ParenType is uninteresting
62cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // TypedefType is uninteresting
63cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
64cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // TypeOfExprType
65cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  typedef __typeof__((static_cast<Types>(0))) typeof_expr; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
66cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
67cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // TypeOfType
68cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  typedef __typeof__(Types) typeof_type;  // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
69cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
70cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // DecltypeType
71cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  typedef decltype((static_cast<Types>(0))) typeof_expr; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
72cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
73cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // RecordType is uninteresting
74cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // EnumType is uninteresting
75cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // ElaboratedType is uninteresting
76cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
77cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // TemplateTypeParmType
78cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  typedef Types template_type_parm; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
79cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
80cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // SubstTemplateTypeParmType is uninteresting
81cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
82cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // TemplateSpecializationType
83cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  typedef pair<Types, int> template_specialization; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
84cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
85cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // InjectedClassName is uninteresting.
86cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
87cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // DependentNameType
88cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  typedef typename Types::type dependent_name; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
89cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
90cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // DependentTemplateSpecializationType
91cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  typedef typename Types::template apply<int> dependent_name_1; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
92cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  typedef typename T::template apply<Types> dependent_name_2; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
93cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
94cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // ObjCObjectType is uninteresting
95cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // ObjCInterfaceType is uninteresting
96cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor  // ObjCObjectPointerType is uninteresting
97d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor};
98bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor
99e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor// FIXME: Test for unexpanded parameter packs in each of the expression nodes.
100e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor
101bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregortemplate<typename ... Types>
102bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregorvoid TestPPNameFunc(int i) {
1039ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor  f(static_cast<Types>(i)); // expected-error{{expression contains unexpanded parameter pack 'Types'}}
104bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor}
1059ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor
106e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor// FIXME: Test for unexpanded parameter packs in declarations.
107a31040f16604849b3b1dc36015056c81bae68ad1Douglas Gregor// FIXME: Attributes?
10856c04588ef3cfa1bbc968fd68de2480a4e66971dDouglas Gregortemplate<typename T, typename... Types>
10956c04588ef3cfa1bbc968fd68de2480a4e66971dDouglas Gregorstruct TestUnexpandedDecls : T{
110e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor  void member_function(Types);  // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
111e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor  void member_function () throw(Types); // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
11256c04588ef3cfa1bbc968fd68de2480a4e66971dDouglas Gregor  operator Types() const; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
113e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor  Types data_member;  // expected-error{{data member type contains unexpanded parameter pack 'Types'}}
114e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor  static Types static_data_member; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
115e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor  unsigned bit_field : static_cast<Types>(0);  // expected-error{{bit-field size contains unexpanded parameter pack 'Types'}}
116399ad970a25efcbfa7111e17f48285a70fba2731Douglas Gregor  static_assert(static_cast<Types>(0), "Boom"); // expected-error{{static assertion contains unexpanded parameter pack 'Types'}}
1170c9e4799fd78d350a037498b2c797f2b2558791cDouglas Gregor
1180c9e4799fd78d350a037498b2c797f2b2558791cDouglas Gregor  enum E0 : Types {  // expected-error{{fixed underlying type contains unexpanded parameter pack 'Types'}}
1190c9e4799fd78d350a037498b2c797f2b2558791cDouglas Gregor    EnumValue = static_cast<Types>(0) // expected-error{{enumerator value contains unexpanded parameter pack 'Types'}}
1200c9e4799fd78d350a037498b2c797f2b2558791cDouglas Gregor  };
12156c04588ef3cfa1bbc968fd68de2480a4e66971dDouglas Gregor
12256c04588ef3cfa1bbc968fd68de2480a4e66971dDouglas Gregor  using typename Types::type; // expected-error{{using declaration contains unexpanded parameter pack 'Types'}}
12356c04588ef3cfa1bbc968fd68de2480a4e66971dDouglas Gregor  using Types::value; // expected-error{{using declaration contains unexpanded parameter pack 'Types'}}
12456c04588ef3cfa1bbc968fd68de2480a4e66971dDouglas Gregor  using T::operator Types; // expected-error{{using declaration contains unexpanded parameter pack 'Types'}}
1256ccab97c17c17f38eb92c7fe02c766508875bd97Douglas Gregor
1266ccab97c17c17f38eb92c7fe02c766508875bd97Douglas Gregor  friend class Types::foo; // expected-error{{friend declaration contains unexpanded parameter pack 'Types'}}
1276ccab97c17c17f38eb92c7fe02c766508875bd97Douglas Gregor  friend void friend_func(Types); // expected-error{{friend declaration contains unexpanded parameter pack 'Types'}}
1286ccab97c17c17f38eb92c7fe02c766508875bd97Douglas Gregor  friend void Types::other_friend_func(int); // expected-error{{friend declaration contains unexpanded parameter pack 'Types'}}
129a31040f16604849b3b1dc36015056c81bae68ad1Douglas Gregor
130a31040f16604849b3b1dc36015056c81bae68ad1Douglas Gregor  void test_initializers() {
131a31040f16604849b3b1dc36015056c81bae68ad1Douglas Gregor    T copy_init = static_cast<Types>(0); // expected-error{{initializer contains unexpanded parameter pack 'Types'}}
132a31040f16604849b3b1dc36015056c81bae68ad1Douglas Gregor    T direct_init(0, static_cast<Types>(0)); // expected-error{{expression contains unexpanded parameter pack 'Types'}}
133a31040f16604849b3b1dc36015056c81bae68ad1Douglas Gregor    T list_init = { static_cast<Types>(0) }; // expected-error{{initializer contains unexpanded parameter pack 'Types'}}
134a31040f16604849b3b1dc36015056c81bae68ad1Douglas Gregor  }
135e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor};
136e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor
137e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor// Test for diagnostics in the presence of multiple unexpanded
138e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor// parameter packs.
1399ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregortemplate<typename T, typename U> struct pair;
1409ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor
1419ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregortemplate<typename ...OuterTypes>
1429ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregorstruct MemberTemplatePPNames {
1439ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor  template<typename ...InnerTypes>
1449ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor  struct Inner {
1459ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor    typedef pair<OuterTypes, InnerTypes>* types; // expected-error{{declaration type contains unexpanded parameter packs 'OuterTypes' and 'InnerTypes'}}
1469ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor
1479ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor    template<typename ...VeryInnerTypes>
1489ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor    struct VeryInner {
1499ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor      typedef pair<pair<VeryInnerTypes, OuterTypes>, pair<InnerTypes, OuterTypes> > types; // expected-error{{declaration type contains unexpanded parameter packs 'VeryInnerTypes', 'OuterTypes', ...}}
1509ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor    };
1519ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor  };
1529ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor};
153e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor
154