blob: c0ad2be6d40e89e75e60a69fb07502e7aaf00e30 [file] [log] [blame]
Douglas Gregorc4633352010-12-15 17:38:57 +00001//===------- SemaTemplateVariadic.cpp - C++ Variadic Templates ------------===/
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//===----------------------------------------------------------------------===/
8//
9// This file implements semantic analysis for C++0x variadic templates.
10//===----------------------------------------------------------------------===/
11
12#include "clang/Sema/Sema.h"
Chandler Carruth55fc8732012-12-04 09:13:33 +000013#include "clang/AST/Expr.h"
14#include "clang/AST/RecursiveASTVisitor.h"
15#include "clang/AST/TypeLoc.h"
Douglas Gregoree8aff02011-01-04 17:33:58 +000016#include "clang/Sema/Lookup.h"
Douglas Gregor7536dd52010-12-20 02:24:11 +000017#include "clang/Sema/ParsedTemplate.h"
Richard Smith612409e2012-07-25 03:56:55 +000018#include "clang/Sema/ScopeInfo.h"
Douglas Gregorc4633352010-12-15 17:38:57 +000019#include "clang/Sema/SemaInternal.h"
Douglas Gregor8491ffe2010-12-20 22:05:00 +000020#include "clang/Sema/Template.h"
Douglas Gregorc4633352010-12-15 17:38:57 +000021
22using namespace clang;
23
Douglas Gregor9ef75892010-12-15 19:43:21 +000024//----------------------------------------------------------------------------
25// Visitor that collects unexpanded parameter packs
26//----------------------------------------------------------------------------
27
Douglas Gregor9ef75892010-12-15 19:43:21 +000028namespace {
29 /// \brief A class that collects unexpanded parameter packs.
30 class CollectUnexpandedParameterPacksVisitor :
31 public RecursiveASTVisitor<CollectUnexpandedParameterPacksVisitor>
32 {
33 typedef RecursiveASTVisitor<CollectUnexpandedParameterPacksVisitor>
34 inherited;
35
Chris Lattner5f9e2722011-07-23 10:55:15 +000036 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded;
Douglas Gregor9ef75892010-12-15 19:43:21 +000037
Richard Smith612409e2012-07-25 03:56:55 +000038 bool InLambda;
39
Douglas Gregor9ef75892010-12-15 19:43:21 +000040 public:
41 explicit CollectUnexpandedParameterPacksVisitor(
Chris Lattner5f9e2722011-07-23 10:55:15 +000042 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded)
Richard Smith612409e2012-07-25 03:56:55 +000043 : Unexpanded(Unexpanded), InLambda(false) { }
Douglas Gregor9ef75892010-12-15 19:43:21 +000044
Douglas Gregora40bc722010-12-20 23:07:20 +000045 bool shouldWalkTypesOfTypeLocs() const { return false; }
46
Douglas Gregor9ef75892010-12-15 19:43:21 +000047 //------------------------------------------------------------------------
48 // Recording occurrences of (unexpanded) parameter packs.
49 //------------------------------------------------------------------------
50
51 /// \brief Record occurrences of template type parameter packs.
52 bool VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) {
53 if (TL.getTypePtr()->isParameterPack())
54 Unexpanded.push_back(std::make_pair(TL.getTypePtr(), TL.getNameLoc()));
55 return true;
56 }
57
58 /// \brief Record occurrences of template type parameter packs
59 /// when we don't have proper source-location information for
60 /// them.
61 ///
62 /// Ideally, this routine would never be used.
63 bool VisitTemplateTypeParmType(TemplateTypeParmType *T) {
64 if (T->isParameterPack())
65 Unexpanded.push_back(std::make_pair(T, SourceLocation()));
66
67 return true;
68 }
69
Douglas Gregora779d9c2011-01-19 21:32:01 +000070 /// \brief Record occurrences of function and non-type template
Douglas Gregor10738d32010-12-23 23:51:58 +000071 /// parameter packs in an expression.
72 bool VisitDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor12c9c002011-01-07 16:43:16 +000073 if (E->getDecl()->isParameterPack())
74 Unexpanded.push_back(std::make_pair(E->getDecl(), E->getLocation()));
Douglas Gregor10738d32010-12-23 23:51:58 +000075
76 return true;
77 }
78
Douglas Gregor61c4d282011-01-05 15:48:55 +000079 /// \brief Record occurrences of template template parameter packs.
80 bool TraverseTemplateName(TemplateName Template) {
81 if (TemplateTemplateParmDecl *TTP
82 = dyn_cast_or_null<TemplateTemplateParmDecl>(
83 Template.getAsTemplateDecl()))
84 if (TTP->isParameterPack())
85 Unexpanded.push_back(std::make_pair(TTP, SourceLocation()));
86
87 return inherited::TraverseTemplateName(Template);
88 }
Douglas Gregor9ef75892010-12-15 19:43:21 +000089
Ted Kremenekebcb57a2012-03-06 20:05:56 +000090 /// \brief Suppress traversal into Objective-C container literal
91 /// elements that are pack expansions.
92 bool TraverseObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
93 if (!E->containsUnexpandedParameterPack())
94 return true;
95
96 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
97 ObjCDictionaryElement Element = E->getKeyValueElement(I);
98 if (Element.isPackExpansion())
99 continue;
100
101 TraverseStmt(Element.Key);
102 TraverseStmt(Element.Value);
103 }
104 return true;
105 }
Douglas Gregor9ef75892010-12-15 19:43:21 +0000106 //------------------------------------------------------------------------
107 // Pruning the search for unexpanded parameter packs.
108 //------------------------------------------------------------------------
109
110 /// \brief Suppress traversal into statements and expressions that
111 /// do not contain unexpanded parameter packs.
112 bool TraverseStmt(Stmt *S) {
Richard Smith612409e2012-07-25 03:56:55 +0000113 Expr *E = dyn_cast_or_null<Expr>(S);
114 if ((E && E->containsUnexpandedParameterPack()) || InLambda)
115 return inherited::TraverseStmt(S);
Douglas Gregor9ef75892010-12-15 19:43:21 +0000116
Richard Smith612409e2012-07-25 03:56:55 +0000117 return true;
Douglas Gregor9ef75892010-12-15 19:43:21 +0000118 }
119
120 /// \brief Suppress traversal into types that do not contain
121 /// unexpanded parameter packs.
122 bool TraverseType(QualType T) {
Richard Smith612409e2012-07-25 03:56:55 +0000123 if ((!T.isNull() && T->containsUnexpandedParameterPack()) || InLambda)
Douglas Gregor9ef75892010-12-15 19:43:21 +0000124 return inherited::TraverseType(T);
125
126 return true;
127 }
128
129 /// \brief Suppress traversel into types with location information
130 /// that do not contain unexpanded parameter packs.
131 bool TraverseTypeLoc(TypeLoc TL) {
Richard Smith612409e2012-07-25 03:56:55 +0000132 if ((!TL.getType().isNull() &&
133 TL.getType()->containsUnexpandedParameterPack()) ||
134 InLambda)
Douglas Gregor9ef75892010-12-15 19:43:21 +0000135 return inherited::TraverseTypeLoc(TL);
136
137 return true;
138 }
139
Douglas Gregorcff163e2010-12-15 21:57:59 +0000140 /// \brief Suppress traversal of non-parameter declarations, since
141 /// they cannot contain unexpanded parameter packs.
142 bool TraverseDecl(Decl *D) {
Richard Smith612409e2012-07-25 03:56:55 +0000143 if ((D && isa<ParmVarDecl>(D)) || InLambda)
Douglas Gregorcff163e2010-12-15 21:57:59 +0000144 return inherited::TraverseDecl(D);
145
Richard Smith612409e2012-07-25 03:56:55 +0000146 return true;
Douglas Gregorcff163e2010-12-15 21:57:59 +0000147 }
Douglas Gregorba68eca2011-01-05 17:40:24 +0000148
149 /// \brief Suppress traversal of template argument pack expansions.
150 bool TraverseTemplateArgument(const TemplateArgument &Arg) {
151 if (Arg.isPackExpansion())
152 return true;
153
154 return inherited::TraverseTemplateArgument(Arg);
155 }
156
157 /// \brief Suppress traversal of template argument pack expansions.
158 bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc) {
159 if (ArgLoc.getArgument().isPackExpansion())
160 return true;
161
162 return inherited::TraverseTemplateArgumentLoc(ArgLoc);
163 }
Richard Smith612409e2012-07-25 03:56:55 +0000164
165 /// \brief Note whether we're traversing a lambda containing an unexpanded
166 /// parameter pack. In this case, the unexpanded pack can occur anywhere,
167 /// including all the places where we normally wouldn't look. Within a
168 /// lambda, we don't propagate the 'contains unexpanded parameter pack' bit
169 /// outside an expression.
170 bool TraverseLambdaExpr(LambdaExpr *Lambda) {
171 // The ContainsUnexpandedParameterPack bit on a lambda is always correct,
172 // even if it's contained within another lambda.
173 if (!Lambda->containsUnexpandedParameterPack())
174 return true;
175
176 bool WasInLambda = InLambda;
177 InLambda = true;
178
179 // If any capture names a function parameter pack, that pack is expanded
180 // when the lambda is expanded.
181 for (LambdaExpr::capture_iterator I = Lambda->capture_begin(),
182 E = Lambda->capture_end(); I != E; ++I)
183 if (VarDecl *VD = I->getCapturedVar())
184 if (VD->isParameterPack())
185 Unexpanded.push_back(std::make_pair(VD, I->getLocation()));
186
187 inherited::TraverseLambdaExpr(Lambda);
188
189 InLambda = WasInLambda;
190 return true;
191 }
Douglas Gregor9ef75892010-12-15 19:43:21 +0000192 };
193}
194
195/// \brief Diagnose all of the unexpanded parameter packs in the given
196/// vector.
Richard Smith612409e2012-07-25 03:56:55 +0000197bool
Douglas Gregor65019ac2011-10-25 03:44:56 +0000198Sema::DiagnoseUnexpandedParameterPacks(SourceLocation Loc,
199 UnexpandedParameterPackContext UPPC,
Bill Wendling4fe5be02012-02-22 09:38:11 +0000200 ArrayRef<UnexpandedParameterPack> Unexpanded) {
Douglas Gregor65019ac2011-10-25 03:44:56 +0000201 if (Unexpanded.empty())
Richard Smith612409e2012-07-25 03:56:55 +0000202 return false;
203
204 // If we are within a lambda expression, that lambda contains an unexpanded
205 // parameter pack, and we are done.
206 // FIXME: Store 'Unexpanded' on the lambda so we don't need to recompute it
207 // later.
208 for (unsigned N = FunctionScopes.size(); N; --N) {
209 if (sema::LambdaScopeInfo *LSI =
210 dyn_cast<sema::LambdaScopeInfo>(FunctionScopes[N-1])) {
211 LSI->ContainsUnexpandedParameterPack = true;
212 return false;
213 }
214 }
Douglas Gregor65019ac2011-10-25 03:44:56 +0000215
Chris Lattner5f9e2722011-07-23 10:55:15 +0000216 SmallVector<SourceLocation, 4> Locations;
217 SmallVector<IdentifierInfo *, 4> Names;
Douglas Gregor9ef75892010-12-15 19:43:21 +0000218 llvm::SmallPtrSet<IdentifierInfo *, 4> NamesKnown;
219
220 for (unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
221 IdentifierInfo *Name = 0;
222 if (const TemplateTypeParmType *TTP
223 = Unexpanded[I].first.dyn_cast<const TemplateTypeParmType *>())
Chandler Carruthb7efff42011-05-01 01:05:51 +0000224 Name = TTP->getIdentifier();
Douglas Gregor9ef75892010-12-15 19:43:21 +0000225 else
226 Name = Unexpanded[I].first.get<NamedDecl *>()->getIdentifier();
227
228 if (Name && NamesKnown.insert(Name))
229 Names.push_back(Name);
230
231 if (Unexpanded[I].second.isValid())
232 Locations.push_back(Unexpanded[I].second);
233 }
234
235 DiagnosticBuilder DB
Douglas Gregor65019ac2011-10-25 03:44:56 +0000236 = Names.size() == 0? Diag(Loc, diag::err_unexpanded_parameter_pack_0)
Douglas Gregor9ef75892010-12-15 19:43:21 +0000237 << (int)UPPC
Douglas Gregor65019ac2011-10-25 03:44:56 +0000238 : Names.size() == 1? Diag(Loc, diag::err_unexpanded_parameter_pack_1)
Douglas Gregor9ef75892010-12-15 19:43:21 +0000239 << (int)UPPC << Names[0]
Douglas Gregor65019ac2011-10-25 03:44:56 +0000240 : Names.size() == 2? Diag(Loc, diag::err_unexpanded_parameter_pack_2)
Douglas Gregor9ef75892010-12-15 19:43:21 +0000241 << (int)UPPC << Names[0] << Names[1]
Douglas Gregor65019ac2011-10-25 03:44:56 +0000242 : Diag(Loc, diag::err_unexpanded_parameter_pack_3_or_more)
Douglas Gregor9ef75892010-12-15 19:43:21 +0000243 << (int)UPPC << Names[0] << Names[1];
244
245 for (unsigned I = 0, N = Locations.size(); I != N; ++I)
246 DB << SourceRange(Locations[I]);
Richard Smith612409e2012-07-25 03:56:55 +0000247 return true;
Douglas Gregor9ef75892010-12-15 19:43:21 +0000248}
249
Douglas Gregorc4633352010-12-15 17:38:57 +0000250bool Sema::DiagnoseUnexpandedParameterPack(SourceLocation Loc,
251 TypeSourceInfo *T,
252 UnexpandedParameterPackContext UPPC) {
253 // C++0x [temp.variadic]p5:
254 // An appearance of a name of a parameter pack that is not expanded is
255 // ill-formed.
256 if (!T->getType()->containsUnexpandedParameterPack())
257 return false;
258
Chris Lattner5f9e2722011-07-23 10:55:15 +0000259 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor9ef75892010-12-15 19:43:21 +0000260 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(
261 T->getTypeLoc());
262 assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
Richard Smith612409e2012-07-25 03:56:55 +0000263 return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
Douglas Gregorc4633352010-12-15 17:38:57 +0000264}
265
266bool Sema::DiagnoseUnexpandedParameterPack(Expr *E,
Douglas Gregor56c04582010-12-16 00:46:58 +0000267 UnexpandedParameterPackContext UPPC) {
Douglas Gregorc4633352010-12-15 17:38:57 +0000268 // C++0x [temp.variadic]p5:
269 // An appearance of a name of a parameter pack that is not expanded is
270 // ill-formed.
271 if (!E->containsUnexpandedParameterPack())
272 return false;
273
Chris Lattner5f9e2722011-07-23 10:55:15 +0000274 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor9ef75892010-12-15 19:43:21 +0000275 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseStmt(E);
276 assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
Richard Smith612409e2012-07-25 03:56:55 +0000277 return DiagnoseUnexpandedParameterPacks(E->getLocStart(), UPPC, Unexpanded);
Douglas Gregorc4633352010-12-15 17:38:57 +0000278}
Douglas Gregor56c04582010-12-16 00:46:58 +0000279
280bool Sema::DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS,
281 UnexpandedParameterPackContext UPPC) {
282 // C++0x [temp.variadic]p5:
283 // An appearance of a name of a parameter pack that is not expanded is
284 // ill-formed.
285 if (!SS.getScopeRep() ||
286 !SS.getScopeRep()->containsUnexpandedParameterPack())
287 return false;
288
Chris Lattner5f9e2722011-07-23 10:55:15 +0000289 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor56c04582010-12-16 00:46:58 +0000290 CollectUnexpandedParameterPacksVisitor(Unexpanded)
291 .TraverseNestedNameSpecifier(SS.getScopeRep());
292 assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
Richard Smith612409e2012-07-25 03:56:55 +0000293 return DiagnoseUnexpandedParameterPacks(SS.getRange().getBegin(),
294 UPPC, Unexpanded);
Douglas Gregor56c04582010-12-16 00:46:58 +0000295}
296
297bool Sema::DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo,
298 UnexpandedParameterPackContext UPPC) {
299 // C++0x [temp.variadic]p5:
300 // An appearance of a name of a parameter pack that is not expanded is
301 // ill-formed.
302 switch (NameInfo.getName().getNameKind()) {
303 case DeclarationName::Identifier:
304 case DeclarationName::ObjCZeroArgSelector:
305 case DeclarationName::ObjCOneArgSelector:
306 case DeclarationName::ObjCMultiArgSelector:
307 case DeclarationName::CXXOperatorName:
308 case DeclarationName::CXXLiteralOperatorName:
309 case DeclarationName::CXXUsingDirective:
310 return false;
311
312 case DeclarationName::CXXConstructorName:
313 case DeclarationName::CXXDestructorName:
314 case DeclarationName::CXXConversionFunctionName:
Douglas Gregor099ffe82010-12-16 17:19:19 +0000315 // FIXME: We shouldn't need this null check!
Douglas Gregor0762bfd2010-12-16 01:40:04 +0000316 if (TypeSourceInfo *TSInfo = NameInfo.getNamedTypeInfo())
317 return DiagnoseUnexpandedParameterPack(NameInfo.getLoc(), TSInfo, UPPC);
318
319 if (!NameInfo.getName().getCXXNameType()->containsUnexpandedParameterPack())
Douglas Gregor56c04582010-12-16 00:46:58 +0000320 return false;
Douglas Gregor0762bfd2010-12-16 01:40:04 +0000321
Douglas Gregor56c04582010-12-16 00:46:58 +0000322 break;
323 }
324
Chris Lattner5f9e2722011-07-23 10:55:15 +0000325 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor56c04582010-12-16 00:46:58 +0000326 CollectUnexpandedParameterPacksVisitor(Unexpanded)
Douglas Gregor0762bfd2010-12-16 01:40:04 +0000327 .TraverseType(NameInfo.getName().getCXXNameType());
Douglas Gregor56c04582010-12-16 00:46:58 +0000328 assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
Richard Smith612409e2012-07-25 03:56:55 +0000329 return DiagnoseUnexpandedParameterPacks(NameInfo.getLoc(), UPPC, Unexpanded);
Douglas Gregor56c04582010-12-16 00:46:58 +0000330}
Douglas Gregor6f526752010-12-16 08:48:57 +0000331
332bool Sema::DiagnoseUnexpandedParameterPack(SourceLocation Loc,
333 TemplateName Template,
334 UnexpandedParameterPackContext UPPC) {
335
336 if (Template.isNull() || !Template.containsUnexpandedParameterPack())
337 return false;
338
Chris Lattner5f9e2722011-07-23 10:55:15 +0000339 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor6f526752010-12-16 08:48:57 +0000340 CollectUnexpandedParameterPacksVisitor(Unexpanded)
341 .TraverseTemplateName(Template);
342 assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
Richard Smith612409e2012-07-25 03:56:55 +0000343 return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
Douglas Gregor6f526752010-12-16 08:48:57 +0000344}
345
Douglas Gregor925910d2011-01-03 20:35:03 +0000346bool Sema::DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg,
347 UnexpandedParameterPackContext UPPC) {
348 if (Arg.getArgument().isNull() ||
349 !Arg.getArgument().containsUnexpandedParameterPack())
350 return false;
351
Chris Lattner5f9e2722011-07-23 10:55:15 +0000352 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor925910d2011-01-03 20:35:03 +0000353 CollectUnexpandedParameterPacksVisitor(Unexpanded)
354 .TraverseTemplateArgumentLoc(Arg);
355 assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
Richard Smith612409e2012-07-25 03:56:55 +0000356 return DiagnoseUnexpandedParameterPacks(Arg.getLocation(), UPPC, Unexpanded);
Douglas Gregor925910d2011-01-03 20:35:03 +0000357}
358
Douglas Gregore02e2622010-12-22 21:19:48 +0000359void Sema::collectUnexpandedParameterPacks(TemplateArgument Arg,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000360 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded) {
Douglas Gregore02e2622010-12-22 21:19:48 +0000361 CollectUnexpandedParameterPacksVisitor(Unexpanded)
362 .TraverseTemplateArgument(Arg);
363}
364
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000365void Sema::collectUnexpandedParameterPacks(TemplateArgumentLoc Arg,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000366 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000367 CollectUnexpandedParameterPacksVisitor(Unexpanded)
368 .TraverseTemplateArgumentLoc(Arg);
369}
370
Douglas Gregorb99268b2010-12-21 00:52:54 +0000371void Sema::collectUnexpandedParameterPacks(QualType T,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000372 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded) {
Douglas Gregorb99268b2010-12-21 00:52:54 +0000373 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(T);
374}
375
Douglas Gregorf90b27a2011-01-03 22:36:02 +0000376void Sema::collectUnexpandedParameterPacks(TypeLoc TL,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000377 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded) {
Douglas Gregorf90b27a2011-01-03 22:36:02 +0000378 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(TL);
379}
380
Douglas Gregor65019ac2011-10-25 03:44:56 +0000381void Sema::collectUnexpandedParameterPacks(CXXScopeSpec &SS,
382 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded) {
383 NestedNameSpecifier *Qualifier = SS.getScopeRep();
384 if (!Qualifier)
385 return;
386
387 NestedNameSpecifierLoc QualifierLoc(Qualifier, SS.location_data());
388 CollectUnexpandedParameterPacksVisitor(Unexpanded)
389 .TraverseNestedNameSpecifierLoc(QualifierLoc);
390}
391
392void Sema::collectUnexpandedParameterPacks(const DeclarationNameInfo &NameInfo,
393 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded) {
394 CollectUnexpandedParameterPacksVisitor(Unexpanded)
395 .TraverseDeclarationNameInfo(NameInfo);
396}
397
398
Douglas Gregor7536dd52010-12-20 02:24:11 +0000399ParsedTemplateArgument
400Sema::ActOnPackExpansion(const ParsedTemplateArgument &Arg,
401 SourceLocation EllipsisLoc) {
402 if (Arg.isInvalid())
403 return Arg;
404
405 switch (Arg.getKind()) {
406 case ParsedTemplateArgument::Type: {
407 TypeResult Result = ActOnPackExpansion(Arg.getAsType(), EllipsisLoc);
408 if (Result.isInvalid())
409 return ParsedTemplateArgument();
410
411 return ParsedTemplateArgument(Arg.getKind(), Result.get().getAsOpaquePtr(),
412 Arg.getLocation());
413 }
414
Douglas Gregorbe230c32011-01-03 17:17:50 +0000415 case ParsedTemplateArgument::NonType: {
416 ExprResult Result = ActOnPackExpansion(Arg.getAsExpr(), EllipsisLoc);
417 if (Result.isInvalid())
418 return ParsedTemplateArgument();
419
420 return ParsedTemplateArgument(Arg.getKind(), Result.get(),
421 Arg.getLocation());
422 }
423
Douglas Gregor7536dd52010-12-20 02:24:11 +0000424 case ParsedTemplateArgument::Template:
Douglas Gregorba68eca2011-01-05 17:40:24 +0000425 if (!Arg.getAsTemplate().get().containsUnexpandedParameterPack()) {
426 SourceRange R(Arg.getLocation());
427 if (Arg.getScopeSpec().isValid())
428 R.setBegin(Arg.getScopeSpec().getBeginLoc());
429 Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
430 << R;
431 return ParsedTemplateArgument();
432 }
433
434 return Arg.getTemplatePackExpansion(EllipsisLoc);
Douglas Gregor7536dd52010-12-20 02:24:11 +0000435 }
436 llvm_unreachable("Unhandled template argument kind?");
Douglas Gregor7536dd52010-12-20 02:24:11 +0000437}
438
439TypeResult Sema::ActOnPackExpansion(ParsedType Type,
440 SourceLocation EllipsisLoc) {
441 TypeSourceInfo *TSInfo;
442 GetTypeFromParser(Type, &TSInfo);
443 if (!TSInfo)
444 return true;
445
David Blaikie66874fb2013-02-21 01:47:18 +0000446 TypeSourceInfo *TSResult = CheckPackExpansion(TSInfo, EllipsisLoc, None);
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000447 if (!TSResult)
448 return true;
449
450 return CreateParsedType(TSResult->getType(), TSResult);
451}
452
David Blaikiedc84cd52013-02-20 22:23:23 +0000453TypeSourceInfo *
454Sema::CheckPackExpansion(TypeSourceInfo *Pattern, SourceLocation EllipsisLoc,
455 Optional<unsigned> NumExpansions) {
Douglas Gregor7536dd52010-12-20 02:24:11 +0000456 // Create the pack expansion type and source-location information.
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000457 QualType Result = CheckPackExpansion(Pattern->getType(),
458 Pattern->getTypeLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +0000459 EllipsisLoc, NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000460 if (Result.isNull())
461 return 0;
462
Douglas Gregor7536dd52010-12-20 02:24:11 +0000463 TypeSourceInfo *TSResult = Context.CreateTypeSourceInfo(Result);
David Blaikie39e6ab42013-02-18 22:06:02 +0000464 PackExpansionTypeLoc TL =
465 TSResult->getTypeLoc().castAs<PackExpansionTypeLoc>();
Douglas Gregor7536dd52010-12-20 02:24:11 +0000466 TL.setEllipsisLoc(EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000467
Douglas Gregor7536dd52010-12-20 02:24:11 +0000468 // Copy over the source-location information from the type.
469 memcpy(TL.getNextTypeLoc().getOpaqueData(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000470 Pattern->getTypeLoc().getOpaqueData(),
471 Pattern->getTypeLoc().getFullDataSize());
472 return TSResult;
Douglas Gregor7536dd52010-12-20 02:24:11 +0000473}
Douglas Gregorb99268b2010-12-21 00:52:54 +0000474
David Blaikiedc84cd52013-02-20 22:23:23 +0000475QualType Sema::CheckPackExpansion(QualType Pattern, SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000476 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +0000477 Optional<unsigned> NumExpansions) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000478 // C++0x [temp.variadic]p5:
479 // The pattern of a pack expansion shall name one or more
480 // parameter packs that are not expanded by a nested pack
481 // expansion.
482 if (!Pattern->containsUnexpandedParameterPack()) {
483 Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
484 << PatternRange;
485 return QualType();
486 }
487
Douglas Gregorcded4f62011-01-14 17:04:44 +0000488 return Context.getPackExpansionType(Pattern, NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000489}
490
Douglas Gregorbe230c32011-01-03 17:17:50 +0000491ExprResult Sema::ActOnPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc) {
David Blaikie66874fb2013-02-21 01:47:18 +0000492 return CheckPackExpansion(Pattern, EllipsisLoc, None);
Douglas Gregor67fd1252011-01-14 21:20:45 +0000493}
494
495ExprResult Sema::CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +0000496 Optional<unsigned> NumExpansions) {
Douglas Gregorbe230c32011-01-03 17:17:50 +0000497 if (!Pattern)
498 return ExprError();
499
500 // C++0x [temp.variadic]p5:
501 // The pattern of a pack expansion shall name one or more
502 // parameter packs that are not expanded by a nested pack
503 // expansion.
504 if (!Pattern->containsUnexpandedParameterPack()) {
505 Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
506 << Pattern->getSourceRange();
507 return ExprError();
508 }
509
510 // Create the pack expansion expression and source-location information.
511 return Owned(new (Context) PackExpansionExpr(Context.DependentTy, Pattern,
Douglas Gregor67fd1252011-01-14 21:20:45 +0000512 EllipsisLoc, NumExpansions));
Douglas Gregorbe230c32011-01-03 17:17:50 +0000513}
Douglas Gregorb99268b2010-12-21 00:52:54 +0000514
Douglas Gregord3731192011-01-10 07:32:04 +0000515/// \brief Retrieve the depth and index of a parameter pack.
516static std::pair<unsigned, unsigned>
517getDepthAndIndex(NamedDecl *ND) {
518 if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(ND))
519 return std::make_pair(TTP->getDepth(), TTP->getIndex());
520
521 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(ND))
522 return std::make_pair(NTTP->getDepth(), NTTP->getIndex());
523
524 TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(ND);
525 return std::make_pair(TTP->getDepth(), TTP->getIndex());
526}
527
David Blaikiedc84cd52013-02-20 22:23:23 +0000528bool Sema::CheckParameterPacksForExpansion(
529 SourceLocation EllipsisLoc, SourceRange PatternRange,
530 ArrayRef<UnexpandedParameterPack> Unexpanded,
531 const MultiLevelTemplateArgumentList &TemplateArgs, bool &ShouldExpand,
532 bool &RetainExpansion, Optional<unsigned> &NumExpansions) {
Douglas Gregorb99268b2010-12-21 00:52:54 +0000533 ShouldExpand = true;
Douglas Gregord3731192011-01-10 07:32:04 +0000534 RetainExpansion = false;
Douglas Gregorb99268b2010-12-21 00:52:54 +0000535 std::pair<IdentifierInfo *, SourceLocation> FirstPack;
536 bool HaveFirstPack = false;
537
David Blaikiea71f9d02011-09-22 02:34:54 +0000538 for (ArrayRef<UnexpandedParameterPack>::iterator i = Unexpanded.begin(),
539 end = Unexpanded.end();
540 i != end; ++i) {
Douglas Gregorb99268b2010-12-21 00:52:54 +0000541 // Compute the depth and index for this parameter pack.
Ted Kremenek9577abc2011-01-23 17:04:59 +0000542 unsigned Depth = 0, Index = 0;
Douglas Gregorb99268b2010-12-21 00:52:54 +0000543 IdentifierInfo *Name;
Douglas Gregor12c9c002011-01-07 16:43:16 +0000544 bool IsFunctionParameterPack = false;
Douglas Gregorb99268b2010-12-21 00:52:54 +0000545
546 if (const TemplateTypeParmType *TTP
David Blaikiea71f9d02011-09-22 02:34:54 +0000547 = i->first.dyn_cast<const TemplateTypeParmType *>()) {
Douglas Gregorb99268b2010-12-21 00:52:54 +0000548 Depth = TTP->getDepth();
549 Index = TTP->getIndex();
Chandler Carruthb7efff42011-05-01 01:05:51 +0000550 Name = TTP->getIdentifier();
Douglas Gregorb99268b2010-12-21 00:52:54 +0000551 } else {
David Blaikiea71f9d02011-09-22 02:34:54 +0000552 NamedDecl *ND = i->first.get<NamedDecl *>();
Douglas Gregord3731192011-01-10 07:32:04 +0000553 if (isa<ParmVarDecl>(ND))
Douglas Gregor12c9c002011-01-07 16:43:16 +0000554 IsFunctionParameterPack = true;
Douglas Gregord3731192011-01-10 07:32:04 +0000555 else
556 llvm::tie(Depth, Index) = getDepthAndIndex(ND);
557
Douglas Gregorb99268b2010-12-21 00:52:54 +0000558 Name = ND->getIdentifier();
559 }
560
Douglas Gregor12c9c002011-01-07 16:43:16 +0000561 // Determine the size of this argument pack.
562 unsigned NewPackSize;
563 if (IsFunctionParameterPack) {
564 // Figure out whether we're instantiating to an argument pack or not.
565 typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
566
567 llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation
568 = CurrentInstantiationScope->findInstantiationOf(
David Blaikiea71f9d02011-09-22 02:34:54 +0000569 i->first.get<NamedDecl *>());
Chris Lattnera70062f2011-02-17 19:38:27 +0000570 if (Instantiation->is<DeclArgumentPack *>()) {
Douglas Gregor12c9c002011-01-07 16:43:16 +0000571 // We could expand this function parameter pack.
572 NewPackSize = Instantiation->get<DeclArgumentPack *>()->size();
573 } else {
574 // We can't expand this function parameter pack, so we can't expand
575 // the pack expansion.
576 ShouldExpand = false;
577 continue;
578 }
579 } else {
580 // If we don't have a template argument at this depth/index, then we
581 // cannot expand the pack expansion. Make a note of this, but we still
582 // want to check any parameter packs we *do* have arguments for.
583 if (Depth >= TemplateArgs.getNumLevels() ||
584 !TemplateArgs.hasTemplateArgument(Depth, Index)) {
585 ShouldExpand = false;
586 continue;
587 }
588
589 // Determine the size of the argument pack.
590 NewPackSize = TemplateArgs(Depth, Index).pack_size();
Douglas Gregorb99268b2010-12-21 00:52:54 +0000591 }
592
Douglas Gregord3731192011-01-10 07:32:04 +0000593 // C++0x [temp.arg.explicit]p9:
594 // Template argument deduction can extend the sequence of template
595 // arguments corresponding to a template parameter pack, even when the
596 // sequence contains explicitly specified template arguments.
Douglas Gregor8619edd2011-01-20 23:15:49 +0000597 if (!IsFunctionParameterPack) {
598 if (NamedDecl *PartialPack
599 = CurrentInstantiationScope->getPartiallySubstitutedPack()){
600 unsigned PartialDepth, PartialIndex;
601 llvm::tie(PartialDepth, PartialIndex) = getDepthAndIndex(PartialPack);
602 if (PartialDepth == Depth && PartialIndex == Index)
603 RetainExpansion = true;
604 }
Douglas Gregord3731192011-01-10 07:32:04 +0000605 }
Douglas Gregor8619edd2011-01-20 23:15:49 +0000606
Douglas Gregorcded4f62011-01-14 17:04:44 +0000607 if (!NumExpansions) {
Douglas Gregorb99268b2010-12-21 00:52:54 +0000608 // The is the first pack we've seen for which we have an argument.
609 // Record it.
610 NumExpansions = NewPackSize;
611 FirstPack.first = Name;
David Blaikiea71f9d02011-09-22 02:34:54 +0000612 FirstPack.second = i->second;
Douglas Gregorb99268b2010-12-21 00:52:54 +0000613 HaveFirstPack = true;
614 continue;
615 }
616
Douglas Gregorcded4f62011-01-14 17:04:44 +0000617 if (NewPackSize != *NumExpansions) {
Douglas Gregorb99268b2010-12-21 00:52:54 +0000618 // C++0x [temp.variadic]p5:
619 // All of the parameter packs expanded by a pack expansion shall have
620 // the same number of arguments specified.
Douglas Gregorcded4f62011-01-14 17:04:44 +0000621 if (HaveFirstPack)
622 Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict)
623 << FirstPack.first << Name << *NumExpansions << NewPackSize
David Blaikiea71f9d02011-09-22 02:34:54 +0000624 << SourceRange(FirstPack.second) << SourceRange(i->second);
Douglas Gregorcded4f62011-01-14 17:04:44 +0000625 else
626 Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict_multilevel)
627 << Name << *NumExpansions << NewPackSize
David Blaikiea71f9d02011-09-22 02:34:54 +0000628 << SourceRange(i->second);
Douglas Gregorb99268b2010-12-21 00:52:54 +0000629 return true;
630 }
631 }
632
633 return false;
634}
Douglas Gregora8bc8c92010-12-23 22:44:42 +0000635
David Blaikiedc84cd52013-02-20 22:23:23 +0000636Optional<unsigned> Sema::getNumArgumentsInExpansion(QualType T,
Douglas Gregor21371ea2011-01-11 03:14:20 +0000637 const MultiLevelTemplateArgumentList &TemplateArgs) {
638 QualType Pattern = cast<PackExpansionType>(T)->getPattern();
Chris Lattner5f9e2722011-07-23 10:55:15 +0000639 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor21371ea2011-01-11 03:14:20 +0000640 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(Pattern);
641
David Blaikiedc84cd52013-02-20 22:23:23 +0000642 Optional<unsigned> Result;
Douglas Gregor21371ea2011-01-11 03:14:20 +0000643 for (unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
644 // Compute the depth and index for this parameter pack.
645 unsigned Depth;
646 unsigned Index;
647
648 if (const TemplateTypeParmType *TTP
649 = Unexpanded[I].first.dyn_cast<const TemplateTypeParmType *>()) {
650 Depth = TTP->getDepth();
651 Index = TTP->getIndex();
652 } else {
653 NamedDecl *ND = Unexpanded[I].first.get<NamedDecl *>();
654 if (isa<ParmVarDecl>(ND)) {
655 // Function parameter pack.
656 typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
657
658 llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation
659 = CurrentInstantiationScope->findInstantiationOf(
660 Unexpanded[I].first.get<NamedDecl *>());
Richard Smith500d7292012-07-18 01:29:05 +0000661 if (Instantiation->is<Decl*>())
662 // The pattern refers to an unexpanded pack. We're not ready to expand
663 // this pack yet.
David Blaikie66874fb2013-02-21 01:47:18 +0000664 return None;
Richard Smith500d7292012-07-18 01:29:05 +0000665
666 unsigned Size = Instantiation->get<DeclArgumentPack *>()->size();
667 assert((!Result || *Result == Size) && "inconsistent pack sizes");
668 Result = Size;
Douglas Gregor21371ea2011-01-11 03:14:20 +0000669 continue;
670 }
671
672 llvm::tie(Depth, Index) = getDepthAndIndex(ND);
673 }
674 if (Depth >= TemplateArgs.getNumLevels() ||
675 !TemplateArgs.hasTemplateArgument(Depth, Index))
Richard Smith500d7292012-07-18 01:29:05 +0000676 // The pattern refers to an unknown template argument. We're not ready to
677 // expand this pack yet.
David Blaikie66874fb2013-02-21 01:47:18 +0000678 return None;
Douglas Gregor21371ea2011-01-11 03:14:20 +0000679
680 // Determine the size of the argument pack.
Richard Smith500d7292012-07-18 01:29:05 +0000681 unsigned Size = TemplateArgs(Depth, Index).pack_size();
682 assert((!Result || *Result == Size) && "inconsistent pack sizes");
683 Result = Size;
Douglas Gregor21371ea2011-01-11 03:14:20 +0000684 }
685
Richard Smith500d7292012-07-18 01:29:05 +0000686 return Result;
Douglas Gregor21371ea2011-01-11 03:14:20 +0000687}
688
Douglas Gregora8bc8c92010-12-23 22:44:42 +0000689bool Sema::containsUnexpandedParameterPacks(Declarator &D) {
690 const DeclSpec &DS = D.getDeclSpec();
691 switch (DS.getTypeSpecType()) {
692 case TST_typename:
Sean Huntdb5d44b2011-05-19 05:37:45 +0000693 case TST_typeofType:
Eli Friedmanb001de72011-10-06 23:00:33 +0000694 case TST_underlyingType:
695 case TST_atomic: {
Douglas Gregora8bc8c92010-12-23 22:44:42 +0000696 QualType T = DS.getRepAsType().get();
697 if (!T.isNull() && T->containsUnexpandedParameterPack())
698 return true;
699 break;
700 }
701
702 case TST_typeofExpr:
703 case TST_decltype:
704 if (DS.getRepAsExpr() &&
705 DS.getRepAsExpr()->containsUnexpandedParameterPack())
706 return true;
707 break;
708
709 case TST_unspecified:
710 case TST_void:
711 case TST_char:
712 case TST_wchar:
713 case TST_char16:
714 case TST_char32:
715 case TST_int:
Richard Smith5a5a9712012-04-04 06:24:32 +0000716 case TST_int128:
Anton Korobeynikovaa4a99b2011-10-14 23:23:15 +0000717 case TST_half:
Douglas Gregora8bc8c92010-12-23 22:44:42 +0000718 case TST_float:
719 case TST_double:
720 case TST_bool:
721 case TST_decimal32:
722 case TST_decimal64:
723 case TST_decimal128:
724 case TST_enum:
725 case TST_union:
726 case TST_struct:
Joao Matos6666ed42012-08-31 18:45:21 +0000727 case TST_interface:
Douglas Gregora8bc8c92010-12-23 22:44:42 +0000728 case TST_class:
729 case TST_auto:
John McCalla5fc4722011-04-09 22:50:59 +0000730 case TST_unknown_anytype:
Guy Benyeib13621d2012-12-18 14:38:23 +0000731 case TST_image1d_t:
732 case TST_image1d_array_t:
733 case TST_image1d_buffer_t:
734 case TST_image2d_t:
735 case TST_image2d_array_t:
736 case TST_image3d_t:
Guy Benyei21f18c42013-02-07 10:55:47 +0000737 case TST_sampler_t:
Guy Benyeie6b9d802013-01-20 12:31:11 +0000738 case TST_event_t:
Douglas Gregora8bc8c92010-12-23 22:44:42 +0000739 case TST_error:
740 break;
741 }
742
743 for (unsigned I = 0, N = D.getNumTypeObjects(); I != N; ++I) {
744 const DeclaratorChunk &Chunk = D.getTypeObject(I);
745 switch (Chunk.Kind) {
746 case DeclaratorChunk::Pointer:
747 case DeclaratorChunk::Reference:
748 case DeclaratorChunk::Paren:
749 // These declarator chunks cannot contain any parameter packs.
750 break;
751
752 case DeclaratorChunk::Array:
753 case DeclaratorChunk::Function:
754 case DeclaratorChunk::BlockPointer:
755 // Syntactically, these kinds of declarator chunks all come after the
756 // declarator-id (conceptually), so the parser should not invoke this
757 // routine at this time.
758 llvm_unreachable("Could not have seen this kind of declarator chunk");
Douglas Gregora8bc8c92010-12-23 22:44:42 +0000759
760 case DeclaratorChunk::MemberPointer:
761 if (Chunk.Mem.Scope().getScopeRep() &&
762 Chunk.Mem.Scope().getScopeRep()->containsUnexpandedParameterPack())
763 return true;
764 break;
765 }
766 }
767
768 return false;
769}
Douglas Gregoree8aff02011-01-04 17:33:58 +0000770
Kaelyn Uhrainf8ec8c92012-01-13 23:10:36 +0000771namespace {
772
773// Callback to only accept typo corrections that refer to parameter packs.
774class ParameterPackValidatorCCC : public CorrectionCandidateCallback {
775 public:
776 virtual bool ValidateCandidate(const TypoCorrection &candidate) {
777 NamedDecl *ND = candidate.getCorrectionDecl();
778 return ND && ND->isParameterPack();
779 }
780};
781
782}
783
Douglas Gregoree8aff02011-01-04 17:33:58 +0000784/// \brief Called when an expression computing the size of a parameter pack
785/// is parsed.
786///
787/// \code
788/// template<typename ...Types> struct count {
789/// static const unsigned value = sizeof...(Types);
790/// };
791/// \endcode
792///
793//
794/// \param OpLoc The location of the "sizeof" keyword.
795/// \param Name The name of the parameter pack whose size will be determined.
796/// \param NameLoc The source location of the name of the parameter pack.
797/// \param RParenLoc The location of the closing parentheses.
798ExprResult Sema::ActOnSizeofParameterPackExpr(Scope *S,
799 SourceLocation OpLoc,
800 IdentifierInfo &Name,
801 SourceLocation NameLoc,
802 SourceLocation RParenLoc) {
803 // C++0x [expr.sizeof]p5:
804 // The identifier in a sizeof... expression shall name a parameter pack.
Douglas Gregoree8aff02011-01-04 17:33:58 +0000805 LookupResult R(*this, &Name, NameLoc, LookupOrdinaryName);
806 LookupName(R, S);
807
808 NamedDecl *ParameterPack = 0;
Kaelyn Uhrainf8ec8c92012-01-13 23:10:36 +0000809 ParameterPackValidatorCCC Validator;
Douglas Gregoree8aff02011-01-04 17:33:58 +0000810 switch (R.getResultKind()) {
811 case LookupResult::Found:
812 ParameterPack = R.getFoundDecl();
813 break;
814
815 case LookupResult::NotFound:
816 case LookupResult::NotFoundInCurrentInstantiation:
Douglas Gregord8bba9c2011-06-28 16:20:02 +0000817 if (TypoCorrection Corrected = CorrectTypo(R.getLookupNameInfo(),
Kaelyn Uhrainf8ec8c92012-01-13 23:10:36 +0000818 R.getLookupKind(), S, 0,
Kaelyn Uhrain16e46dd2012-01-31 23:49:25 +0000819 Validator)) {
David Blaikie4e4d0842012-03-11 07:00:24 +0000820 std::string CorrectedQuotedStr(Corrected.getQuoted(getLangOpts()));
Kaelyn Uhrainf8ec8c92012-01-13 23:10:36 +0000821 ParameterPack = Corrected.getCorrectionDecl();
822 Diag(NameLoc, diag::err_sizeof_pack_no_pack_name_suggest)
823 << &Name << CorrectedQuotedStr
824 << FixItHint::CreateReplacement(
David Blaikie4e4d0842012-03-11 07:00:24 +0000825 NameLoc, Corrected.getAsString(getLangOpts()));
Kaelyn Uhrainf8ec8c92012-01-13 23:10:36 +0000826 Diag(ParameterPack->getLocation(), diag::note_parameter_pack_here)
827 << CorrectedQuotedStr;
Douglas Gregoree8aff02011-01-04 17:33:58 +0000828 }
829
830 case LookupResult::FoundOverloaded:
831 case LookupResult::FoundUnresolvedValue:
832 break;
833
834 case LookupResult::Ambiguous:
835 DiagnoseAmbiguousLookup(R);
836 return ExprError();
837 }
838
Douglas Gregor1fe85ea2011-01-05 21:11:38 +0000839 if (!ParameterPack || !ParameterPack->isParameterPack()) {
Douglas Gregoree8aff02011-01-04 17:33:58 +0000840 Diag(NameLoc, diag::err_sizeof_pack_no_pack_name)
841 << &Name;
842 return ExprError();
843 }
844
Nick Lewyckyb7e5eec2013-02-02 00:25:55 +0000845 MarkAnyDeclReferenced(OpLoc, ParameterPack, true);
Eli Friedman88530d52012-03-01 21:32:56 +0000846
Douglas Gregoree8aff02011-01-04 17:33:58 +0000847 return new (Context) SizeOfPackExpr(Context.getSizeType(), OpLoc,
848 ParameterPack, NameLoc, RParenLoc);
849}