Douglas Gregor | b55fdf8 | 2010-12-15 17:38:57 +0000 | [diff] [blame] | 1 | //===------- 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 Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 13 | #include "TypeLocBuilder.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 14 | #include "clang/AST/Expr.h" |
| 15 | #include "clang/AST/RecursiveASTVisitor.h" |
| 16 | #include "clang/AST/TypeLoc.h" |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 17 | #include "clang/Sema/Lookup.h" |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 18 | #include "clang/Sema/ParsedTemplate.h" |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 19 | #include "clang/Sema/ScopeInfo.h" |
Douglas Gregor | b55fdf8 | 2010-12-15 17:38:57 +0000 | [diff] [blame] | 20 | #include "clang/Sema/SemaInternal.h" |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 21 | #include "clang/Sema/Template.h" |
Douglas Gregor | b55fdf8 | 2010-12-15 17:38:57 +0000 | [diff] [blame] | 22 | |
| 23 | using namespace clang; |
| 24 | |
Douglas Gregor | 1da294a | 2010-12-15 19:43:21 +0000 | [diff] [blame] | 25 | //---------------------------------------------------------------------------- |
| 26 | // Visitor that collects unexpanded parameter packs |
| 27 | //---------------------------------------------------------------------------- |
| 28 | |
Douglas Gregor | 1da294a | 2010-12-15 19:43:21 +0000 | [diff] [blame] | 29 | namespace { |
| 30 | /// \brief A class that collects unexpanded parameter packs. |
| 31 | class CollectUnexpandedParameterPacksVisitor : |
| 32 | public RecursiveASTVisitor<CollectUnexpandedParameterPacksVisitor> |
| 33 | { |
| 34 | typedef RecursiveASTVisitor<CollectUnexpandedParameterPacksVisitor> |
| 35 | inherited; |
| 36 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 37 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded; |
Douglas Gregor | 1da294a | 2010-12-15 19:43:21 +0000 | [diff] [blame] | 38 | |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 39 | bool InLambda; |
| 40 | |
Douglas Gregor | 1da294a | 2010-12-15 19:43:21 +0000 | [diff] [blame] | 41 | public: |
| 42 | explicit CollectUnexpandedParameterPacksVisitor( |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 43 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded) |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 44 | : Unexpanded(Unexpanded), InLambda(false) { } |
Douglas Gregor | 1da294a | 2010-12-15 19:43:21 +0000 | [diff] [blame] | 45 | |
Douglas Gregor | 15b4ec2 | 2010-12-20 23:07:20 +0000 | [diff] [blame] | 46 | bool shouldWalkTypesOfTypeLocs() const { return false; } |
| 47 | |
Douglas Gregor | 1da294a | 2010-12-15 19:43:21 +0000 | [diff] [blame] | 48 | //------------------------------------------------------------------------ |
| 49 | // Recording occurrences of (unexpanded) parameter packs. |
| 50 | //------------------------------------------------------------------------ |
| 51 | |
| 52 | /// \brief Record occurrences of template type parameter packs. |
| 53 | bool VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
| 54 | if (TL.getTypePtr()->isParameterPack()) |
| 55 | Unexpanded.push_back(std::make_pair(TL.getTypePtr(), TL.getNameLoc())); |
| 56 | return true; |
| 57 | } |
| 58 | |
| 59 | /// \brief Record occurrences of template type parameter packs |
| 60 | /// when we don't have proper source-location information for |
| 61 | /// them. |
| 62 | /// |
| 63 | /// Ideally, this routine would never be used. |
| 64 | bool VisitTemplateTypeParmType(TemplateTypeParmType *T) { |
| 65 | if (T->isParameterPack()) |
| 66 | Unexpanded.push_back(std::make_pair(T, SourceLocation())); |
| 67 | |
| 68 | return true; |
| 69 | } |
| 70 | |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 71 | /// \brief Record occurrences of function and non-type template |
Douglas Gregor | da3cc0d | 2010-12-23 23:51:58 +0000 | [diff] [blame] | 72 | /// parameter packs in an expression. |
| 73 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 74 | if (E->getDecl()->isParameterPack()) |
| 75 | Unexpanded.push_back(std::make_pair(E->getDecl(), E->getLocation())); |
Douglas Gregor | da3cc0d | 2010-12-23 23:51:58 +0000 | [diff] [blame] | 76 | |
| 77 | return true; |
| 78 | } |
| 79 | |
Douglas Gregor | f550077 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 80 | /// \brief Record occurrences of template template parameter packs. |
| 81 | bool TraverseTemplateName(TemplateName Template) { |
| 82 | if (TemplateTemplateParmDecl *TTP |
| 83 | = dyn_cast_or_null<TemplateTemplateParmDecl>( |
| 84 | Template.getAsTemplateDecl())) |
| 85 | if (TTP->isParameterPack()) |
| 86 | Unexpanded.push_back(std::make_pair(TTP, SourceLocation())); |
| 87 | |
| 88 | return inherited::TraverseTemplateName(Template); |
| 89 | } |
Douglas Gregor | 1da294a | 2010-12-15 19:43:21 +0000 | [diff] [blame] | 90 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 91 | /// \brief Suppress traversal into Objective-C container literal |
| 92 | /// elements that are pack expansions. |
| 93 | bool TraverseObjCDictionaryLiteral(ObjCDictionaryLiteral *E) { |
| 94 | if (!E->containsUnexpandedParameterPack()) |
| 95 | return true; |
| 96 | |
| 97 | for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) { |
| 98 | ObjCDictionaryElement Element = E->getKeyValueElement(I); |
| 99 | if (Element.isPackExpansion()) |
| 100 | continue; |
| 101 | |
| 102 | TraverseStmt(Element.Key); |
| 103 | TraverseStmt(Element.Value); |
| 104 | } |
| 105 | return true; |
| 106 | } |
Douglas Gregor | 1da294a | 2010-12-15 19:43:21 +0000 | [diff] [blame] | 107 | //------------------------------------------------------------------------ |
| 108 | // Pruning the search for unexpanded parameter packs. |
| 109 | //------------------------------------------------------------------------ |
| 110 | |
| 111 | /// \brief Suppress traversal into statements and expressions that |
| 112 | /// do not contain unexpanded parameter packs. |
| 113 | bool TraverseStmt(Stmt *S) { |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 114 | Expr *E = dyn_cast_or_null<Expr>(S); |
| 115 | if ((E && E->containsUnexpandedParameterPack()) || InLambda) |
| 116 | return inherited::TraverseStmt(S); |
Douglas Gregor | 1da294a | 2010-12-15 19:43:21 +0000 | [diff] [blame] | 117 | |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 118 | return true; |
Douglas Gregor | 1da294a | 2010-12-15 19:43:21 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | /// \brief Suppress traversal into types that do not contain |
| 122 | /// unexpanded parameter packs. |
| 123 | bool TraverseType(QualType T) { |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 124 | if ((!T.isNull() && T->containsUnexpandedParameterPack()) || InLambda) |
Douglas Gregor | 1da294a | 2010-12-15 19:43:21 +0000 | [diff] [blame] | 125 | return inherited::TraverseType(T); |
| 126 | |
| 127 | return true; |
| 128 | } |
| 129 | |
| 130 | /// \brief Suppress traversel into types with location information |
| 131 | /// that do not contain unexpanded parameter packs. |
| 132 | bool TraverseTypeLoc(TypeLoc TL) { |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 133 | if ((!TL.getType().isNull() && |
| 134 | TL.getType()->containsUnexpandedParameterPack()) || |
| 135 | InLambda) |
Douglas Gregor | 1da294a | 2010-12-15 19:43:21 +0000 | [diff] [blame] | 136 | return inherited::TraverseTypeLoc(TL); |
| 137 | |
| 138 | return true; |
| 139 | } |
| 140 | |
Douglas Gregor | a8461bb | 2010-12-15 21:57:59 +0000 | [diff] [blame] | 141 | /// \brief Suppress traversal of non-parameter declarations, since |
| 142 | /// they cannot contain unexpanded parameter packs. |
| 143 | bool TraverseDecl(Decl *D) { |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 144 | if ((D && isa<ParmVarDecl>(D)) || InLambda) |
Douglas Gregor | a8461bb | 2010-12-15 21:57:59 +0000 | [diff] [blame] | 145 | return inherited::TraverseDecl(D); |
| 146 | |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 147 | return true; |
Douglas Gregor | a8461bb | 2010-12-15 21:57:59 +0000 | [diff] [blame] | 148 | } |
Douglas Gregor | eb29d18 | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 149 | |
| 150 | /// \brief Suppress traversal of template argument pack expansions. |
| 151 | bool TraverseTemplateArgument(const TemplateArgument &Arg) { |
| 152 | if (Arg.isPackExpansion()) |
| 153 | return true; |
| 154 | |
| 155 | return inherited::TraverseTemplateArgument(Arg); |
| 156 | } |
| 157 | |
| 158 | /// \brief Suppress traversal of template argument pack expansions. |
| 159 | bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc) { |
| 160 | if (ArgLoc.getArgument().isPackExpansion()) |
| 161 | return true; |
| 162 | |
| 163 | return inherited::TraverseTemplateArgumentLoc(ArgLoc); |
| 164 | } |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 165 | |
| 166 | /// \brief Note whether we're traversing a lambda containing an unexpanded |
| 167 | /// parameter pack. In this case, the unexpanded pack can occur anywhere, |
| 168 | /// including all the places where we normally wouldn't look. Within a |
| 169 | /// lambda, we don't propagate the 'contains unexpanded parameter pack' bit |
| 170 | /// outside an expression. |
| 171 | bool TraverseLambdaExpr(LambdaExpr *Lambda) { |
| 172 | // The ContainsUnexpandedParameterPack bit on a lambda is always correct, |
| 173 | // even if it's contained within another lambda. |
| 174 | if (!Lambda->containsUnexpandedParameterPack()) |
| 175 | return true; |
| 176 | |
| 177 | bool WasInLambda = InLambda; |
| 178 | InLambda = true; |
| 179 | |
| 180 | // If any capture names a function parameter pack, that pack is expanded |
| 181 | // when the lambda is expanded. |
| 182 | for (LambdaExpr::capture_iterator I = Lambda->capture_begin(), |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 183 | E = Lambda->capture_end(); |
| 184 | I != E; ++I) { |
| 185 | if (I->capturesVariable()) { |
| 186 | VarDecl *VD = I->getCapturedVar(); |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 187 | if (VD->isParameterPack()) |
| 188 | Unexpanded.push_back(std::make_pair(VD, I->getLocation())); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 189 | } |
| 190 | } |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 191 | |
| 192 | inherited::TraverseLambdaExpr(Lambda); |
| 193 | |
| 194 | InLambda = WasInLambda; |
| 195 | return true; |
| 196 | } |
Douglas Gregor | 1da294a | 2010-12-15 19:43:21 +0000 | [diff] [blame] | 197 | }; |
| 198 | } |
| 199 | |
Richard Smith | 36ee9fb | 2014-08-11 23:30:23 +0000 | [diff] [blame] | 200 | /// \brief Determine whether it's possible for an unexpanded parameter pack to |
| 201 | /// be valid in this location. This only happens when we're in a declaration |
| 202 | /// that is nested within an expression that could be expanded, such as a |
| 203 | /// lambda-expression within a function call. |
| 204 | /// |
| 205 | /// This is conservatively correct, but may claim that some unexpanded packs are |
| 206 | /// permitted when they are not. |
| 207 | bool Sema::isUnexpandedParameterPackPermitted() { |
| 208 | for (auto *SI : FunctionScopes) |
| 209 | if (isa<sema::LambdaScopeInfo>(SI)) |
| 210 | return true; |
| 211 | return false; |
| 212 | } |
| 213 | |
Douglas Gregor | 1da294a | 2010-12-15 19:43:21 +0000 | [diff] [blame] | 214 | /// \brief Diagnose all of the unexpanded parameter packs in the given |
| 215 | /// vector. |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 216 | bool |
Douglas Gregor | 4a2a8f7 | 2011-10-25 03:44:56 +0000 | [diff] [blame] | 217 | Sema::DiagnoseUnexpandedParameterPacks(SourceLocation Loc, |
| 218 | UnexpandedParameterPackContext UPPC, |
Bill Wendling | 8ac06af | 2012-02-22 09:38:11 +0000 | [diff] [blame] | 219 | ArrayRef<UnexpandedParameterPack> Unexpanded) { |
Douglas Gregor | 4a2a8f7 | 2011-10-25 03:44:56 +0000 | [diff] [blame] | 220 | if (Unexpanded.empty()) |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 221 | return false; |
| 222 | |
| 223 | // If we are within a lambda expression, that lambda contains an unexpanded |
| 224 | // parameter pack, and we are done. |
| 225 | // FIXME: Store 'Unexpanded' on the lambda so we don't need to recompute it |
| 226 | // later. |
| 227 | for (unsigned N = FunctionScopes.size(); N; --N) { |
| 228 | if (sema::LambdaScopeInfo *LSI = |
| 229 | dyn_cast<sema::LambdaScopeInfo>(FunctionScopes[N-1])) { |
| 230 | LSI->ContainsUnexpandedParameterPack = true; |
| 231 | return false; |
| 232 | } |
| 233 | } |
Douglas Gregor | 4a2a8f7 | 2011-10-25 03:44:56 +0000 | [diff] [blame] | 234 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 235 | SmallVector<SourceLocation, 4> Locations; |
| 236 | SmallVector<IdentifierInfo *, 4> Names; |
Douglas Gregor | 1da294a | 2010-12-15 19:43:21 +0000 | [diff] [blame] | 237 | llvm::SmallPtrSet<IdentifierInfo *, 4> NamesKnown; |
| 238 | |
| 239 | for (unsigned I = 0, N = Unexpanded.size(); I != N; ++I) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 240 | IdentifierInfo *Name = nullptr; |
Douglas Gregor | 1da294a | 2010-12-15 19:43:21 +0000 | [diff] [blame] | 241 | if (const TemplateTypeParmType *TTP |
| 242 | = Unexpanded[I].first.dyn_cast<const TemplateTypeParmType *>()) |
Chandler Carruth | dde65ea | 2011-05-01 01:05:51 +0000 | [diff] [blame] | 243 | Name = TTP->getIdentifier(); |
Douglas Gregor | 1da294a | 2010-12-15 19:43:21 +0000 | [diff] [blame] | 244 | else |
| 245 | Name = Unexpanded[I].first.get<NamedDecl *>()->getIdentifier(); |
| 246 | |
| 247 | if (Name && NamesKnown.insert(Name)) |
| 248 | Names.push_back(Name); |
| 249 | |
| 250 | if (Unexpanded[I].second.isValid()) |
| 251 | Locations.push_back(Unexpanded[I].second); |
| 252 | } |
| 253 | |
| 254 | DiagnosticBuilder DB |
Douglas Gregor | 4a2a8f7 | 2011-10-25 03:44:56 +0000 | [diff] [blame] | 255 | = Names.size() == 0? Diag(Loc, diag::err_unexpanded_parameter_pack_0) |
Douglas Gregor | 1da294a | 2010-12-15 19:43:21 +0000 | [diff] [blame] | 256 | << (int)UPPC |
Douglas Gregor | 4a2a8f7 | 2011-10-25 03:44:56 +0000 | [diff] [blame] | 257 | : Names.size() == 1? Diag(Loc, diag::err_unexpanded_parameter_pack_1) |
Douglas Gregor | 1da294a | 2010-12-15 19:43:21 +0000 | [diff] [blame] | 258 | << (int)UPPC << Names[0] |
Douglas Gregor | 4a2a8f7 | 2011-10-25 03:44:56 +0000 | [diff] [blame] | 259 | : Names.size() == 2? Diag(Loc, diag::err_unexpanded_parameter_pack_2) |
Douglas Gregor | 1da294a | 2010-12-15 19:43:21 +0000 | [diff] [blame] | 260 | << (int)UPPC << Names[0] << Names[1] |
Douglas Gregor | 4a2a8f7 | 2011-10-25 03:44:56 +0000 | [diff] [blame] | 261 | : Diag(Loc, diag::err_unexpanded_parameter_pack_3_or_more) |
Douglas Gregor | 1da294a | 2010-12-15 19:43:21 +0000 | [diff] [blame] | 262 | << (int)UPPC << Names[0] << Names[1]; |
| 263 | |
| 264 | for (unsigned I = 0, N = Locations.size(); I != N; ++I) |
| 265 | DB << SourceRange(Locations[I]); |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 266 | return true; |
Douglas Gregor | 1da294a | 2010-12-15 19:43:21 +0000 | [diff] [blame] | 267 | } |
| 268 | |
Douglas Gregor | b55fdf8 | 2010-12-15 17:38:57 +0000 | [diff] [blame] | 269 | bool Sema::DiagnoseUnexpandedParameterPack(SourceLocation Loc, |
| 270 | TypeSourceInfo *T, |
| 271 | UnexpandedParameterPackContext UPPC) { |
| 272 | // C++0x [temp.variadic]p5: |
| 273 | // An appearance of a name of a parameter pack that is not expanded is |
| 274 | // ill-formed. |
| 275 | if (!T->getType()->containsUnexpandedParameterPack()) |
| 276 | return false; |
| 277 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 278 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 1da294a | 2010-12-15 19:43:21 +0000 | [diff] [blame] | 279 | CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc( |
| 280 | T->getTypeLoc()); |
| 281 | assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs"); |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 282 | return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded); |
Douglas Gregor | b55fdf8 | 2010-12-15 17:38:57 +0000 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | bool Sema::DiagnoseUnexpandedParameterPack(Expr *E, |
Douglas Gregor | c435653 | 2010-12-16 00:46:58 +0000 | [diff] [blame] | 286 | UnexpandedParameterPackContext UPPC) { |
Douglas Gregor | b55fdf8 | 2010-12-15 17:38:57 +0000 | [diff] [blame] | 287 | // C++0x [temp.variadic]p5: |
| 288 | // An appearance of a name of a parameter pack that is not expanded is |
| 289 | // ill-formed. |
| 290 | if (!E->containsUnexpandedParameterPack()) |
| 291 | return false; |
| 292 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 293 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 1da294a | 2010-12-15 19:43:21 +0000 | [diff] [blame] | 294 | CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseStmt(E); |
| 295 | assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs"); |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 296 | return DiagnoseUnexpandedParameterPacks(E->getLocStart(), UPPC, Unexpanded); |
Douglas Gregor | b55fdf8 | 2010-12-15 17:38:57 +0000 | [diff] [blame] | 297 | } |
Douglas Gregor | c435653 | 2010-12-16 00:46:58 +0000 | [diff] [blame] | 298 | |
| 299 | bool Sema::DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS, |
| 300 | UnexpandedParameterPackContext UPPC) { |
| 301 | // C++0x [temp.variadic]p5: |
| 302 | // An appearance of a name of a parameter pack that is not expanded is |
| 303 | // ill-formed. |
| 304 | if (!SS.getScopeRep() || |
| 305 | !SS.getScopeRep()->containsUnexpandedParameterPack()) |
| 306 | return false; |
| 307 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 308 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | c435653 | 2010-12-16 00:46:58 +0000 | [diff] [blame] | 309 | CollectUnexpandedParameterPacksVisitor(Unexpanded) |
| 310 | .TraverseNestedNameSpecifier(SS.getScopeRep()); |
| 311 | assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs"); |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 312 | return DiagnoseUnexpandedParameterPacks(SS.getRange().getBegin(), |
| 313 | UPPC, Unexpanded); |
Douglas Gregor | c435653 | 2010-12-16 00:46:58 +0000 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | bool Sema::DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo, |
| 317 | UnexpandedParameterPackContext UPPC) { |
| 318 | // C++0x [temp.variadic]p5: |
| 319 | // An appearance of a name of a parameter pack that is not expanded is |
| 320 | // ill-formed. |
| 321 | switch (NameInfo.getName().getNameKind()) { |
| 322 | case DeclarationName::Identifier: |
| 323 | case DeclarationName::ObjCZeroArgSelector: |
| 324 | case DeclarationName::ObjCOneArgSelector: |
| 325 | case DeclarationName::ObjCMultiArgSelector: |
| 326 | case DeclarationName::CXXOperatorName: |
| 327 | case DeclarationName::CXXLiteralOperatorName: |
| 328 | case DeclarationName::CXXUsingDirective: |
| 329 | return false; |
| 330 | |
| 331 | case DeclarationName::CXXConstructorName: |
| 332 | case DeclarationName::CXXDestructorName: |
| 333 | case DeclarationName::CXXConversionFunctionName: |
Douglas Gregor | 062ecac | 2010-12-16 17:19:19 +0000 | [diff] [blame] | 334 | // FIXME: We shouldn't need this null check! |
Douglas Gregor | 6ab34af | 2010-12-16 01:40:04 +0000 | [diff] [blame] | 335 | if (TypeSourceInfo *TSInfo = NameInfo.getNamedTypeInfo()) |
| 336 | return DiagnoseUnexpandedParameterPack(NameInfo.getLoc(), TSInfo, UPPC); |
| 337 | |
| 338 | if (!NameInfo.getName().getCXXNameType()->containsUnexpandedParameterPack()) |
Douglas Gregor | c435653 | 2010-12-16 00:46:58 +0000 | [diff] [blame] | 339 | return false; |
Douglas Gregor | 6ab34af | 2010-12-16 01:40:04 +0000 | [diff] [blame] | 340 | |
Douglas Gregor | c435653 | 2010-12-16 00:46:58 +0000 | [diff] [blame] | 341 | break; |
| 342 | } |
| 343 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 344 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | c435653 | 2010-12-16 00:46:58 +0000 | [diff] [blame] | 345 | CollectUnexpandedParameterPacksVisitor(Unexpanded) |
Douglas Gregor | 6ab34af | 2010-12-16 01:40:04 +0000 | [diff] [blame] | 346 | .TraverseType(NameInfo.getName().getCXXNameType()); |
Douglas Gregor | c435653 | 2010-12-16 00:46:58 +0000 | [diff] [blame] | 347 | assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs"); |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 348 | return DiagnoseUnexpandedParameterPacks(NameInfo.getLoc(), UPPC, Unexpanded); |
Douglas Gregor | c435653 | 2010-12-16 00:46:58 +0000 | [diff] [blame] | 349 | } |
Douglas Gregor | 6ff1fbf | 2010-12-16 08:48:57 +0000 | [diff] [blame] | 350 | |
| 351 | bool Sema::DiagnoseUnexpandedParameterPack(SourceLocation Loc, |
| 352 | TemplateName Template, |
| 353 | UnexpandedParameterPackContext UPPC) { |
| 354 | |
| 355 | if (Template.isNull() || !Template.containsUnexpandedParameterPack()) |
| 356 | return false; |
| 357 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 358 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 6ff1fbf | 2010-12-16 08:48:57 +0000 | [diff] [blame] | 359 | CollectUnexpandedParameterPacksVisitor(Unexpanded) |
| 360 | .TraverseTemplateName(Template); |
| 361 | assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs"); |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 362 | return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded); |
Douglas Gregor | 6ff1fbf | 2010-12-16 08:48:57 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Douglas Gregor | 1440693 | 2011-01-03 20:35:03 +0000 | [diff] [blame] | 365 | bool Sema::DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg, |
| 366 | UnexpandedParameterPackContext UPPC) { |
| 367 | if (Arg.getArgument().isNull() || |
| 368 | !Arg.getArgument().containsUnexpandedParameterPack()) |
| 369 | return false; |
| 370 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 371 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 1440693 | 2011-01-03 20:35:03 +0000 | [diff] [blame] | 372 | CollectUnexpandedParameterPacksVisitor(Unexpanded) |
| 373 | .TraverseTemplateArgumentLoc(Arg); |
| 374 | assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs"); |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 375 | return DiagnoseUnexpandedParameterPacks(Arg.getLocation(), UPPC, Unexpanded); |
Douglas Gregor | 1440693 | 2011-01-03 20:35:03 +0000 | [diff] [blame] | 376 | } |
| 377 | |
Douglas Gregor | 0f3feb4 | 2010-12-22 21:19:48 +0000 | [diff] [blame] | 378 | void Sema::collectUnexpandedParameterPacks(TemplateArgument Arg, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 379 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded) { |
Douglas Gregor | 0f3feb4 | 2010-12-22 21:19:48 +0000 | [diff] [blame] | 380 | CollectUnexpandedParameterPacksVisitor(Unexpanded) |
| 381 | .TraverseTemplateArgument(Arg); |
| 382 | } |
| 383 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 384 | void Sema::collectUnexpandedParameterPacks(TemplateArgumentLoc Arg, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 385 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 386 | CollectUnexpandedParameterPacksVisitor(Unexpanded) |
| 387 | .TraverseTemplateArgumentLoc(Arg); |
| 388 | } |
| 389 | |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 390 | void Sema::collectUnexpandedParameterPacks(QualType T, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 391 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded) { |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 392 | CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(T); |
| 393 | } |
| 394 | |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 395 | void Sema::collectUnexpandedParameterPacks(TypeLoc TL, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 396 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded) { |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 397 | CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(TL); |
| 398 | } |
| 399 | |
Douglas Gregor | 4a2a8f7 | 2011-10-25 03:44:56 +0000 | [diff] [blame] | 400 | void Sema::collectUnexpandedParameterPacks(CXXScopeSpec &SS, |
| 401 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded) { |
| 402 | NestedNameSpecifier *Qualifier = SS.getScopeRep(); |
| 403 | if (!Qualifier) |
| 404 | return; |
| 405 | |
| 406 | NestedNameSpecifierLoc QualifierLoc(Qualifier, SS.location_data()); |
| 407 | CollectUnexpandedParameterPacksVisitor(Unexpanded) |
| 408 | .TraverseNestedNameSpecifierLoc(QualifierLoc); |
| 409 | } |
| 410 | |
| 411 | void Sema::collectUnexpandedParameterPacks(const DeclarationNameInfo &NameInfo, |
| 412 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded) { |
| 413 | CollectUnexpandedParameterPacksVisitor(Unexpanded) |
| 414 | .TraverseDeclarationNameInfo(NameInfo); |
| 415 | } |
| 416 | |
| 417 | |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 418 | ParsedTemplateArgument |
| 419 | Sema::ActOnPackExpansion(const ParsedTemplateArgument &Arg, |
| 420 | SourceLocation EllipsisLoc) { |
| 421 | if (Arg.isInvalid()) |
| 422 | return Arg; |
| 423 | |
| 424 | switch (Arg.getKind()) { |
| 425 | case ParsedTemplateArgument::Type: { |
| 426 | TypeResult Result = ActOnPackExpansion(Arg.getAsType(), EllipsisLoc); |
| 427 | if (Result.isInvalid()) |
| 428 | return ParsedTemplateArgument(); |
| 429 | |
| 430 | return ParsedTemplateArgument(Arg.getKind(), Result.get().getAsOpaquePtr(), |
| 431 | Arg.getLocation()); |
| 432 | } |
| 433 | |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 434 | case ParsedTemplateArgument::NonType: { |
| 435 | ExprResult Result = ActOnPackExpansion(Arg.getAsExpr(), EllipsisLoc); |
| 436 | if (Result.isInvalid()) |
| 437 | return ParsedTemplateArgument(); |
| 438 | |
| 439 | return ParsedTemplateArgument(Arg.getKind(), Result.get(), |
| 440 | Arg.getLocation()); |
| 441 | } |
| 442 | |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 443 | case ParsedTemplateArgument::Template: |
Douglas Gregor | eb29d18 | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 444 | if (!Arg.getAsTemplate().get().containsUnexpandedParameterPack()) { |
| 445 | SourceRange R(Arg.getLocation()); |
| 446 | if (Arg.getScopeSpec().isValid()) |
| 447 | R.setBegin(Arg.getScopeSpec().getBeginLoc()); |
| 448 | Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs) |
| 449 | << R; |
| 450 | return ParsedTemplateArgument(); |
| 451 | } |
| 452 | |
| 453 | return Arg.getTemplatePackExpansion(EllipsisLoc); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 454 | } |
| 455 | llvm_unreachable("Unhandled template argument kind?"); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | TypeResult Sema::ActOnPackExpansion(ParsedType Type, |
| 459 | SourceLocation EllipsisLoc) { |
| 460 | TypeSourceInfo *TSInfo; |
| 461 | GetTypeFromParser(Type, &TSInfo); |
| 462 | if (!TSInfo) |
| 463 | return true; |
| 464 | |
David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 465 | TypeSourceInfo *TSResult = CheckPackExpansion(TSInfo, EllipsisLoc, None); |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 466 | if (!TSResult) |
| 467 | return true; |
| 468 | |
| 469 | return CreateParsedType(TSResult->getType(), TSResult); |
| 470 | } |
| 471 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 472 | TypeSourceInfo * |
| 473 | Sema::CheckPackExpansion(TypeSourceInfo *Pattern, SourceLocation EllipsisLoc, |
| 474 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 475 | // Create the pack expansion type and source-location information. |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 476 | QualType Result = CheckPackExpansion(Pattern->getType(), |
| 477 | Pattern->getTypeLoc().getSourceRange(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 478 | EllipsisLoc, NumExpansions); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 479 | if (Result.isNull()) |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 480 | return nullptr; |
Eli Friedman | 7152fbe | 2013-06-07 20:31:48 +0000 | [diff] [blame] | 481 | |
| 482 | TypeLocBuilder TLB; |
| 483 | TLB.pushFullCopy(Pattern->getTypeLoc()); |
| 484 | PackExpansionTypeLoc TL = TLB.push<PackExpansionTypeLoc>(Result); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 485 | TL.setEllipsisLoc(EllipsisLoc); |
Eli Friedman | 7152fbe | 2013-06-07 20:31:48 +0000 | [diff] [blame] | 486 | |
| 487 | return TLB.getTypeSourceInfo(Context, Result); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 488 | } |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 489 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 490 | QualType Sema::CheckPackExpansion(QualType Pattern, SourceRange PatternRange, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 491 | SourceLocation EllipsisLoc, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 492 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 493 | // C++0x [temp.variadic]p5: |
| 494 | // The pattern of a pack expansion shall name one or more |
| 495 | // parameter packs that are not expanded by a nested pack |
| 496 | // expansion. |
| 497 | if (!Pattern->containsUnexpandedParameterPack()) { |
| 498 | Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs) |
| 499 | << PatternRange; |
| 500 | return QualType(); |
| 501 | } |
| 502 | |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 503 | return Context.getPackExpansionType(Pattern, NumExpansions); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 504 | } |
| 505 | |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 506 | ExprResult Sema::ActOnPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc) { |
David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 507 | return CheckPackExpansion(Pattern, EllipsisLoc, None); |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | ExprResult Sema::CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 511 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 512 | if (!Pattern) |
| 513 | return ExprError(); |
| 514 | |
| 515 | // C++0x [temp.variadic]p5: |
| 516 | // The pattern of a pack expansion shall name one or more |
| 517 | // parameter packs that are not expanded by a nested pack |
| 518 | // expansion. |
| 519 | if (!Pattern->containsUnexpandedParameterPack()) { |
| 520 | Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs) |
| 521 | << Pattern->getSourceRange(); |
| 522 | return ExprError(); |
| 523 | } |
| 524 | |
| 525 | // Create the pack expansion expression and source-location information. |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 526 | return new (Context) |
| 527 | PackExpansionExpr(Context.DependentTy, Pattern, EllipsisLoc, NumExpansions); |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 528 | } |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 529 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 530 | /// \brief Retrieve the depth and index of a parameter pack. |
| 531 | static std::pair<unsigned, unsigned> |
| 532 | getDepthAndIndex(NamedDecl *ND) { |
| 533 | if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(ND)) |
| 534 | return std::make_pair(TTP->getDepth(), TTP->getIndex()); |
| 535 | |
| 536 | if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(ND)) |
| 537 | return std::make_pair(NTTP->getDepth(), NTTP->getIndex()); |
| 538 | |
| 539 | TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(ND); |
| 540 | return std::make_pair(TTP->getDepth(), TTP->getIndex()); |
| 541 | } |
| 542 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 543 | bool Sema::CheckParameterPacksForExpansion( |
| 544 | SourceLocation EllipsisLoc, SourceRange PatternRange, |
| 545 | ArrayRef<UnexpandedParameterPack> Unexpanded, |
| 546 | const MultiLevelTemplateArgumentList &TemplateArgs, bool &ShouldExpand, |
| 547 | bool &RetainExpansion, Optional<unsigned> &NumExpansions) { |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 548 | ShouldExpand = true; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 549 | RetainExpansion = false; |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 550 | std::pair<IdentifierInfo *, SourceLocation> FirstPack; |
| 551 | bool HaveFirstPack = false; |
| 552 | |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 553 | for (ArrayRef<UnexpandedParameterPack>::iterator i = Unexpanded.begin(), |
| 554 | end = Unexpanded.end(); |
| 555 | i != end; ++i) { |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 556 | // Compute the depth and index for this parameter pack. |
Ted Kremenek | 582a099 | 2011-01-23 17:04:59 +0000 | [diff] [blame] | 557 | unsigned Depth = 0, Index = 0; |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 558 | IdentifierInfo *Name; |
Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 559 | bool IsFunctionParameterPack = false; |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 560 | |
| 561 | if (const TemplateTypeParmType *TTP |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 562 | = i->first.dyn_cast<const TemplateTypeParmType *>()) { |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 563 | Depth = TTP->getDepth(); |
| 564 | Index = TTP->getIndex(); |
Chandler Carruth | dde65ea | 2011-05-01 01:05:51 +0000 | [diff] [blame] | 565 | Name = TTP->getIdentifier(); |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 566 | } else { |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 567 | NamedDecl *ND = i->first.get<NamedDecl *>(); |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 568 | if (isa<ParmVarDecl>(ND)) |
Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 569 | IsFunctionParameterPack = true; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 570 | else |
Benjamin Kramer | 867ea1d | 2014-03-02 13:01:17 +0000 | [diff] [blame] | 571 | std::tie(Depth, Index) = getDepthAndIndex(ND); |
| 572 | |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 573 | Name = ND->getIdentifier(); |
| 574 | } |
| 575 | |
Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 576 | // Determine the size of this argument pack. |
| 577 | unsigned NewPackSize; |
| 578 | if (IsFunctionParameterPack) { |
| 579 | // Figure out whether we're instantiating to an argument pack or not. |
| 580 | typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack; |
| 581 | |
| 582 | llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation |
| 583 | = CurrentInstantiationScope->findInstantiationOf( |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 584 | i->first.get<NamedDecl *>()); |
Chris Lattner | 15a776f | 2011-02-17 19:38:27 +0000 | [diff] [blame] | 585 | if (Instantiation->is<DeclArgumentPack *>()) { |
Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 586 | // We could expand this function parameter pack. |
| 587 | NewPackSize = Instantiation->get<DeclArgumentPack *>()->size(); |
| 588 | } else { |
| 589 | // We can't expand this function parameter pack, so we can't expand |
| 590 | // the pack expansion. |
| 591 | ShouldExpand = false; |
| 592 | continue; |
| 593 | } |
| 594 | } else { |
| 595 | // If we don't have a template argument at this depth/index, then we |
| 596 | // cannot expand the pack expansion. Make a note of this, but we still |
| 597 | // want to check any parameter packs we *do* have arguments for. |
| 598 | if (Depth >= TemplateArgs.getNumLevels() || |
| 599 | !TemplateArgs.hasTemplateArgument(Depth, Index)) { |
| 600 | ShouldExpand = false; |
| 601 | continue; |
| 602 | } |
| 603 | |
| 604 | // Determine the size of the argument pack. |
| 605 | NewPackSize = TemplateArgs(Depth, Index).pack_size(); |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 606 | } |
| 607 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 608 | // C++0x [temp.arg.explicit]p9: |
| 609 | // Template argument deduction can extend the sequence of template |
| 610 | // arguments corresponding to a template parameter pack, even when the |
| 611 | // sequence contains explicitly specified template arguments. |
Douglas Gregor | 63dad4d | 2011-01-20 23:15:49 +0000 | [diff] [blame] | 612 | if (!IsFunctionParameterPack) { |
| 613 | if (NamedDecl *PartialPack |
| 614 | = CurrentInstantiationScope->getPartiallySubstitutedPack()){ |
| 615 | unsigned PartialDepth, PartialIndex; |
Benjamin Kramer | 867ea1d | 2014-03-02 13:01:17 +0000 | [diff] [blame] | 616 | std::tie(PartialDepth, PartialIndex) = getDepthAndIndex(PartialPack); |
Douglas Gregor | 63dad4d | 2011-01-20 23:15:49 +0000 | [diff] [blame] | 617 | if (PartialDepth == Depth && PartialIndex == Index) |
| 618 | RetainExpansion = true; |
| 619 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 620 | } |
Douglas Gregor | 63dad4d | 2011-01-20 23:15:49 +0000 | [diff] [blame] | 621 | |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 622 | if (!NumExpansions) { |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 623 | // The is the first pack we've seen for which we have an argument. |
| 624 | // Record it. |
| 625 | NumExpansions = NewPackSize; |
| 626 | FirstPack.first = Name; |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 627 | FirstPack.second = i->second; |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 628 | HaveFirstPack = true; |
| 629 | continue; |
| 630 | } |
| 631 | |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 632 | if (NewPackSize != *NumExpansions) { |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 633 | // C++0x [temp.variadic]p5: |
| 634 | // All of the parameter packs expanded by a pack expansion shall have |
| 635 | // the same number of arguments specified. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 636 | if (HaveFirstPack) |
| 637 | Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict) |
| 638 | << FirstPack.first << Name << *NumExpansions << NewPackSize |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 639 | << SourceRange(FirstPack.second) << SourceRange(i->second); |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 640 | else |
| 641 | Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict_multilevel) |
| 642 | << Name << *NumExpansions << NewPackSize |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 643 | << SourceRange(i->second); |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 644 | return true; |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | return false; |
| 649 | } |
Douglas Gregor | 27b4c16 | 2010-12-23 22:44:42 +0000 | [diff] [blame] | 650 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 651 | Optional<unsigned> Sema::getNumArgumentsInExpansion(QualType T, |
Douglas Gregor | 5cde386 | 2011-01-11 03:14:20 +0000 | [diff] [blame] | 652 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
| 653 | QualType Pattern = cast<PackExpansionType>(T)->getPattern(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 654 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 5cde386 | 2011-01-11 03:14:20 +0000 | [diff] [blame] | 655 | CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(Pattern); |
| 656 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 657 | Optional<unsigned> Result; |
Douglas Gregor | 5cde386 | 2011-01-11 03:14:20 +0000 | [diff] [blame] | 658 | for (unsigned I = 0, N = Unexpanded.size(); I != N; ++I) { |
| 659 | // Compute the depth and index for this parameter pack. |
| 660 | unsigned Depth; |
| 661 | unsigned Index; |
| 662 | |
| 663 | if (const TemplateTypeParmType *TTP |
| 664 | = Unexpanded[I].first.dyn_cast<const TemplateTypeParmType *>()) { |
| 665 | Depth = TTP->getDepth(); |
| 666 | Index = TTP->getIndex(); |
| 667 | } else { |
| 668 | NamedDecl *ND = Unexpanded[I].first.get<NamedDecl *>(); |
| 669 | if (isa<ParmVarDecl>(ND)) { |
| 670 | // Function parameter pack. |
| 671 | typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack; |
| 672 | |
| 673 | llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation |
| 674 | = CurrentInstantiationScope->findInstantiationOf( |
| 675 | Unexpanded[I].first.get<NamedDecl *>()); |
Richard Smith | 198223b | 2012-07-18 01:29:05 +0000 | [diff] [blame] | 676 | if (Instantiation->is<Decl*>()) |
| 677 | // The pattern refers to an unexpanded pack. We're not ready to expand |
| 678 | // this pack yet. |
David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 679 | return None; |
Richard Smith | 198223b | 2012-07-18 01:29:05 +0000 | [diff] [blame] | 680 | |
| 681 | unsigned Size = Instantiation->get<DeclArgumentPack *>()->size(); |
| 682 | assert((!Result || *Result == Size) && "inconsistent pack sizes"); |
| 683 | Result = Size; |
Douglas Gregor | 5cde386 | 2011-01-11 03:14:20 +0000 | [diff] [blame] | 684 | continue; |
| 685 | } |
Benjamin Kramer | 867ea1d | 2014-03-02 13:01:17 +0000 | [diff] [blame] | 686 | |
| 687 | std::tie(Depth, Index) = getDepthAndIndex(ND); |
Douglas Gregor | 5cde386 | 2011-01-11 03:14:20 +0000 | [diff] [blame] | 688 | } |
| 689 | if (Depth >= TemplateArgs.getNumLevels() || |
| 690 | !TemplateArgs.hasTemplateArgument(Depth, Index)) |
Richard Smith | 198223b | 2012-07-18 01:29:05 +0000 | [diff] [blame] | 691 | // The pattern refers to an unknown template argument. We're not ready to |
| 692 | // expand this pack yet. |
David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 693 | return None; |
Douglas Gregor | 5cde386 | 2011-01-11 03:14:20 +0000 | [diff] [blame] | 694 | |
| 695 | // Determine the size of the argument pack. |
Richard Smith | 198223b | 2012-07-18 01:29:05 +0000 | [diff] [blame] | 696 | unsigned Size = TemplateArgs(Depth, Index).pack_size(); |
| 697 | assert((!Result || *Result == Size) && "inconsistent pack sizes"); |
| 698 | Result = Size; |
Douglas Gregor | 5cde386 | 2011-01-11 03:14:20 +0000 | [diff] [blame] | 699 | } |
| 700 | |
Richard Smith | 198223b | 2012-07-18 01:29:05 +0000 | [diff] [blame] | 701 | return Result; |
Douglas Gregor | 5cde386 | 2011-01-11 03:14:20 +0000 | [diff] [blame] | 702 | } |
| 703 | |
Douglas Gregor | 27b4c16 | 2010-12-23 22:44:42 +0000 | [diff] [blame] | 704 | bool Sema::containsUnexpandedParameterPacks(Declarator &D) { |
| 705 | const DeclSpec &DS = D.getDeclSpec(); |
| 706 | switch (DS.getTypeSpecType()) { |
| 707 | case TST_typename: |
Alexis Hunt | 4a25707 | 2011-05-19 05:37:45 +0000 | [diff] [blame] | 708 | case TST_typeofType: |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 709 | case TST_underlyingType: |
| 710 | case TST_atomic: { |
Douglas Gregor | 27b4c16 | 2010-12-23 22:44:42 +0000 | [diff] [blame] | 711 | QualType T = DS.getRepAsType().get(); |
| 712 | if (!T.isNull() && T->containsUnexpandedParameterPack()) |
| 713 | return true; |
| 714 | break; |
| 715 | } |
| 716 | |
| 717 | case TST_typeofExpr: |
| 718 | case TST_decltype: |
| 719 | if (DS.getRepAsExpr() && |
| 720 | DS.getRepAsExpr()->containsUnexpandedParameterPack()) |
| 721 | return true; |
| 722 | break; |
| 723 | |
| 724 | case TST_unspecified: |
| 725 | case TST_void: |
| 726 | case TST_char: |
| 727 | case TST_wchar: |
| 728 | case TST_char16: |
| 729 | case TST_char32: |
| 730 | case TST_int: |
Richard Smith | f016bbc | 2012-04-04 06:24:32 +0000 | [diff] [blame] | 731 | case TST_int128: |
Anton Korobeynikov | f0c267e | 2011-10-14 23:23:15 +0000 | [diff] [blame] | 732 | case TST_half: |
Douglas Gregor | 27b4c16 | 2010-12-23 22:44:42 +0000 | [diff] [blame] | 733 | case TST_float: |
| 734 | case TST_double: |
| 735 | case TST_bool: |
| 736 | case TST_decimal32: |
| 737 | case TST_decimal64: |
| 738 | case TST_decimal128: |
| 739 | case TST_enum: |
| 740 | case TST_union: |
| 741 | case TST_struct: |
Joao Matos | dc86f94 | 2012-08-31 18:45:21 +0000 | [diff] [blame] | 742 | case TST_interface: |
Douglas Gregor | 27b4c16 | 2010-12-23 22:44:42 +0000 | [diff] [blame] | 743 | case TST_class: |
| 744 | case TST_auto: |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 745 | case TST_decltype_auto: |
John McCall | 3943973 | 2011-04-09 22:50:59 +0000 | [diff] [blame] | 746 | case TST_unknown_anytype: |
Douglas Gregor | 27b4c16 | 2010-12-23 22:44:42 +0000 | [diff] [blame] | 747 | case TST_error: |
| 748 | break; |
| 749 | } |
Larisse Voufo | 2e84650 | 2014-08-29 21:08:16 +0000 | [diff] [blame] | 750 | |
Douglas Gregor | 27b4c16 | 2010-12-23 22:44:42 +0000 | [diff] [blame] | 751 | for (unsigned I = 0, N = D.getNumTypeObjects(); I != N; ++I) { |
| 752 | const DeclaratorChunk &Chunk = D.getTypeObject(I); |
| 753 | switch (Chunk.Kind) { |
| 754 | case DeclaratorChunk::Pointer: |
| 755 | case DeclaratorChunk::Reference: |
| 756 | case DeclaratorChunk::Paren: |
Larisse Voufo | 2e84650 | 2014-08-29 21:08:16 +0000 | [diff] [blame] | 757 | case DeclaratorChunk::BlockPointer: |
Douglas Gregor | 27b4c16 | 2010-12-23 22:44:42 +0000 | [diff] [blame] | 758 | // These declarator chunks cannot contain any parameter packs. |
| 759 | break; |
| 760 | |
| 761 | case DeclaratorChunk::Array: |
Larisse Voufo | 2e84650 | 2014-08-29 21:08:16 +0000 | [diff] [blame] | 762 | if (Chunk.Arr.NumElts && |
| 763 | Chunk.Arr.NumElts->containsUnexpandedParameterPack()) |
| 764 | return true; |
| 765 | break; |
Douglas Gregor | 27b4c16 | 2010-12-23 22:44:42 +0000 | [diff] [blame] | 766 | case DeclaratorChunk::Function: |
Larisse Voufo | 2e84650 | 2014-08-29 21:08:16 +0000 | [diff] [blame] | 767 | for (unsigned i = 0, e = Chunk.Fun.NumParams; i != e; ++i) { |
| 768 | ParmVarDecl *Param = cast<ParmVarDecl>(Chunk.Fun.Params[i].Param); |
| 769 | QualType ParamTy = Param->getType(); |
| 770 | assert(!ParamTy.isNull() && "Couldn't parse type?"); |
| 771 | if (ParamTy->containsUnexpandedParameterPack()) return true; |
| 772 | } |
| 773 | |
| 774 | if (Chunk.Fun.getExceptionSpecType() == EST_Dynamic) { |
| 775 | for (unsigned i = 0; i != Chunk.Fun.NumExceptions; ++i) { |
| 776 | if (Chunk.Fun.Exceptions[i] |
| 777 | .Ty.get() |
| 778 | ->containsUnexpandedParameterPack()) |
| 779 | return true; |
| 780 | } |
| 781 | } else if (Chunk.Fun.getExceptionSpecType() == EST_ComputedNoexcept && |
| 782 | Chunk.Fun.NoexceptExpr->containsUnexpandedParameterPack()) |
| 783 | return true; |
| 784 | |
| 785 | if (Chunk.Fun.hasTrailingReturnType() && |
| 786 | Chunk.Fun.getTrailingReturnType() |
| 787 | .get() |
| 788 | ->containsUnexpandedParameterPack()) |
| 789 | return true; |
| 790 | break; |
| 791 | |
Douglas Gregor | 27b4c16 | 2010-12-23 22:44:42 +0000 | [diff] [blame] | 792 | case DeclaratorChunk::MemberPointer: |
| 793 | if (Chunk.Mem.Scope().getScopeRep() && |
| 794 | Chunk.Mem.Scope().getScopeRep()->containsUnexpandedParameterPack()) |
| 795 | return true; |
| 796 | break; |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | return false; |
| 801 | } |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 802 | |
Kaelyn Uhrain | 637b5b3 | 2012-01-13 23:10:36 +0000 | [diff] [blame] | 803 | namespace { |
| 804 | |
| 805 | // Callback to only accept typo corrections that refer to parameter packs. |
| 806 | class ParameterPackValidatorCCC : public CorrectionCandidateCallback { |
| 807 | public: |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 808 | bool ValidateCandidate(const TypoCorrection &candidate) override { |
Kaelyn Uhrain | 637b5b3 | 2012-01-13 23:10:36 +0000 | [diff] [blame] | 809 | NamedDecl *ND = candidate.getCorrectionDecl(); |
| 810 | return ND && ND->isParameterPack(); |
| 811 | } |
| 812 | }; |
| 813 | |
| 814 | } |
| 815 | |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 816 | /// \brief Called when an expression computing the size of a parameter pack |
| 817 | /// is parsed. |
| 818 | /// |
| 819 | /// \code |
| 820 | /// template<typename ...Types> struct count { |
| 821 | /// static const unsigned value = sizeof...(Types); |
| 822 | /// }; |
| 823 | /// \endcode |
| 824 | /// |
| 825 | // |
| 826 | /// \param OpLoc The location of the "sizeof" keyword. |
| 827 | /// \param Name The name of the parameter pack whose size will be determined. |
| 828 | /// \param NameLoc The source location of the name of the parameter pack. |
| 829 | /// \param RParenLoc The location of the closing parentheses. |
| 830 | ExprResult Sema::ActOnSizeofParameterPackExpr(Scope *S, |
| 831 | SourceLocation OpLoc, |
| 832 | IdentifierInfo &Name, |
| 833 | SourceLocation NameLoc, |
| 834 | SourceLocation RParenLoc) { |
| 835 | // C++0x [expr.sizeof]p5: |
| 836 | // The identifier in a sizeof... expression shall name a parameter pack. |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 837 | LookupResult R(*this, &Name, NameLoc, LookupOrdinaryName); |
| 838 | LookupName(R, S); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 839 | |
| 840 | NamedDecl *ParameterPack = nullptr; |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 841 | switch (R.getResultKind()) { |
| 842 | case LookupResult::Found: |
| 843 | ParameterPack = R.getFoundDecl(); |
| 844 | break; |
| 845 | |
| 846 | case LookupResult::NotFound: |
| 847 | case LookupResult::NotFoundInCurrentInstantiation: |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame^] | 848 | if (TypoCorrection Corrected = |
| 849 | CorrectTypo(R.getLookupNameInfo(), R.getLookupKind(), S, nullptr, |
| 850 | llvm::make_unique<ParameterPackValidatorCCC>(), |
| 851 | CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 852 | diagnoseTypo(Corrected, |
| 853 | PDiag(diag::err_sizeof_pack_no_pack_name_suggest) << &Name, |
| 854 | PDiag(diag::note_parameter_pack_here)); |
Kaelyn Uhrain | 637b5b3 | 2012-01-13 23:10:36 +0000 | [diff] [blame] | 855 | ParameterPack = Corrected.getCorrectionDecl(); |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 856 | } |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 857 | |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 858 | case LookupResult::FoundOverloaded: |
| 859 | case LookupResult::FoundUnresolvedValue: |
| 860 | break; |
| 861 | |
| 862 | case LookupResult::Ambiguous: |
| 863 | DiagnoseAmbiguousLookup(R); |
| 864 | return ExprError(); |
| 865 | } |
| 866 | |
Douglas Gregor | 3c6bd2a | 2011-01-05 21:11:38 +0000 | [diff] [blame] | 867 | if (!ParameterPack || !ParameterPack->isParameterPack()) { |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 868 | Diag(NameLoc, diag::err_sizeof_pack_no_pack_name) |
| 869 | << &Name; |
| 870 | return ExprError(); |
| 871 | } |
| 872 | |
Nick Lewycky | 45b5052 | 2013-02-02 00:25:55 +0000 | [diff] [blame] | 873 | MarkAnyDeclReferenced(OpLoc, ParameterPack, true); |
Eli Friedman | 23b1be9 | 2012-03-01 21:32:56 +0000 | [diff] [blame] | 874 | |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 875 | return new (Context) SizeOfPackExpr(Context.getSizeType(), OpLoc, |
| 876 | ParameterPack, NameLoc, RParenLoc); |
| 877 | } |
Eli Friedman | 94e9eaa | 2013-06-20 04:11:21 +0000 | [diff] [blame] | 878 | |
| 879 | TemplateArgumentLoc |
| 880 | Sema::getTemplateArgumentPackExpansionPattern( |
| 881 | TemplateArgumentLoc OrigLoc, |
| 882 | SourceLocation &Ellipsis, Optional<unsigned> &NumExpansions) const { |
| 883 | const TemplateArgument &Argument = OrigLoc.getArgument(); |
| 884 | assert(Argument.isPackExpansion()); |
| 885 | switch (Argument.getKind()) { |
| 886 | case TemplateArgument::Type: { |
| 887 | // FIXME: We shouldn't ever have to worry about missing |
| 888 | // type-source info! |
| 889 | TypeSourceInfo *ExpansionTSInfo = OrigLoc.getTypeSourceInfo(); |
| 890 | if (!ExpansionTSInfo) |
| 891 | ExpansionTSInfo = Context.getTrivialTypeSourceInfo(Argument.getAsType(), |
| 892 | Ellipsis); |
| 893 | PackExpansionTypeLoc Expansion = |
| 894 | ExpansionTSInfo->getTypeLoc().castAs<PackExpansionTypeLoc>(); |
| 895 | Ellipsis = Expansion.getEllipsisLoc(); |
| 896 | |
| 897 | TypeLoc Pattern = Expansion.getPatternLoc(); |
| 898 | NumExpansions = Expansion.getTypePtr()->getNumExpansions(); |
| 899 | |
| 900 | // We need to copy the TypeLoc because TemplateArgumentLocs store a |
| 901 | // TypeSourceInfo. |
| 902 | // FIXME: Find some way to avoid the copy? |
| 903 | TypeLocBuilder TLB; |
| 904 | TLB.pushFullCopy(Pattern); |
| 905 | TypeSourceInfo *PatternTSInfo = |
| 906 | TLB.getTypeSourceInfo(Context, Pattern.getType()); |
| 907 | return TemplateArgumentLoc(TemplateArgument(Pattern.getType()), |
| 908 | PatternTSInfo); |
| 909 | } |
| 910 | |
| 911 | case TemplateArgument::Expression: { |
| 912 | PackExpansionExpr *Expansion |
| 913 | = cast<PackExpansionExpr>(Argument.getAsExpr()); |
| 914 | Expr *Pattern = Expansion->getPattern(); |
| 915 | Ellipsis = Expansion->getEllipsisLoc(); |
| 916 | NumExpansions = Expansion->getNumExpansions(); |
| 917 | return TemplateArgumentLoc(Pattern, Pattern); |
| 918 | } |
| 919 | |
| 920 | case TemplateArgument::TemplateExpansion: |
| 921 | Ellipsis = OrigLoc.getTemplateEllipsisLoc(); |
| 922 | NumExpansions = Argument.getNumTemplateExpansions(); |
| 923 | return TemplateArgumentLoc(Argument.getPackExpansionPattern(), |
| 924 | OrigLoc.getTemplateQualifierLoc(), |
| 925 | OrigLoc.getTemplateNameLoc()); |
| 926 | |
| 927 | case TemplateArgument::Declaration: |
| 928 | case TemplateArgument::NullPtr: |
| 929 | case TemplateArgument::Template: |
| 930 | case TemplateArgument::Integral: |
| 931 | case TemplateArgument::Pack: |
| 932 | case TemplateArgument::Null: |
| 933 | return TemplateArgumentLoc(); |
| 934 | } |
| 935 | |
| 936 | llvm_unreachable("Invalid TemplateArgument Kind!"); |
| 937 | } |