p5.cpp revision 399ad970a25efcbfa7111e17f48285a70fba2731
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// FIXME: Test for unexpanded parameter packs in declarations.
107template<typename... Types>
108struct TestUnexpandedDecls {
109  void member_function(Types);  // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
110  void member_function () throw(Types); // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
111  Types data_member;  // expected-error{{data member type contains unexpanded parameter pack 'Types'}}
112  static Types static_data_member; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
113  unsigned bit_field : static_cast<Types>(0);  // expected-error{{bit-field size contains unexpanded parameter pack 'Types'}}
114  static_assert(static_cast<Types>(0), "Boom"); // expected-error{{static assertion contains unexpanded parameter pack 'Types'}}
115};
116
117// Test for diagnostics in the presence of multiple unexpanded
118// parameter packs.
119template<typename T, typename U> struct pair;
120
121template<typename ...OuterTypes>
122struct MemberTemplatePPNames {
123  template<typename ...InnerTypes>
124  struct Inner {
125    typedef pair<OuterTypes, InnerTypes>* types; // expected-error{{declaration type contains unexpanded parameter packs 'OuterTypes' and 'InnerTypes'}}
126
127    template<typename ...VeryInnerTypes>
128    struct VeryInner {
129      typedef pair<pair<VeryInnerTypes, OuterTypes>, pair<InnerTypes, OuterTypes> > types; // expected-error{{declaration type contains unexpanded parameter packs 'VeryInnerTypes', 'OuterTypes', ...}}
130    };
131  };
132};
133
134