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