1 //===--- ParseCXXInlineMethods.cpp - C++ class inline methods parsing------===//
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 //
10 //  This file implements parsing for C++ class inline methods.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/Parse/Parser.h"
15 #include "RAIIObjectsForParser.h"
16 #include "clang/AST/DeclTemplate.h"
17 #include "clang/Parse/ParseDiagnostic.h"
18 #include "clang/Sema/DeclSpec.h"
19 #include "clang/Sema/Scope.h"
20 using namespace clang;
21 
22 /// ParseCXXInlineMethodDef - We parsed and verified that the specified
23 /// Declarator is a well formed C++ inline method definition. Now lex its body
24 /// and store its tokens for parsing after the C++ class is complete.
25 NamedDecl *Parser::ParseCXXInlineMethodDef(AccessSpecifier AS,
26                                       AttributeList *AccessAttrs,
27                                       ParsingDeclarator &D,
28                                       const ParsedTemplateInfo &TemplateInfo,
29                                       const VirtSpecifiers& VS,
30                                       FunctionDefinitionKind DefinitionKind,
31                                       ExprResult& Init) {
32   assert(D.isFunctionDeclarator() && "This isn't a function declarator!");
33   assert((Tok.is(tok::l_brace) || Tok.is(tok::colon) || Tok.is(tok::kw_try) ||
34           Tok.is(tok::equal)) &&
35          "Current token not a '{', ':', '=', or 'try'!");
36 
37   MultiTemplateParamsArg TemplateParams(
38       TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->data()
39                                   : nullptr,
40       TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->size() : 0);
41 
42   NamedDecl *FnD;
43   D.setFunctionDefinitionKind(DefinitionKind);
44   if (D.getDeclSpec().isFriendSpecified())
45     FnD = Actions.ActOnFriendFunctionDecl(getCurScope(), D,
46                                           TemplateParams);
47   else {
48     FnD = Actions.ActOnCXXMemberDeclarator(getCurScope(), AS, D,
49                                            TemplateParams, nullptr,
50                                            VS, ICIS_NoInit);
51     if (FnD) {
52       Actions.ProcessDeclAttributeList(getCurScope(), FnD, AccessAttrs);
53       bool TypeSpecContainsAuto = D.getDeclSpec().containsPlaceholderType();
54       if (Init.isUsable())
55         Actions.AddInitializerToDecl(FnD, Init.get(), false,
56                                      TypeSpecContainsAuto);
57       else
58         Actions.ActOnUninitializedDecl(FnD, TypeSpecContainsAuto);
59     }
60   }
61 
62   HandleMemberFunctionDeclDelays(D, FnD);
63 
64   D.complete(FnD);
65 
66   if (TryConsumeToken(tok::equal)) {
67     if (!FnD) {
68       SkipUntil(tok::semi);
69       return nullptr;
70     }
71 
72     bool Delete = false;
73     SourceLocation KWLoc;
74     if (TryConsumeToken(tok::kw_delete, KWLoc)) {
75       Diag(KWLoc, getLangOpts().CPlusPlus11
76                       ? diag::warn_cxx98_compat_deleted_function
77                       : diag::ext_deleted_function);
78       Actions.SetDeclDeleted(FnD, KWLoc);
79       Delete = true;
80     } else if (TryConsumeToken(tok::kw_default, KWLoc)) {
81       Diag(KWLoc, getLangOpts().CPlusPlus11
82                       ? diag::warn_cxx98_compat_defaulted_function
83                       : diag::ext_defaulted_function);
84       Actions.SetDeclDefaulted(FnD, KWLoc);
85     } else {
86       llvm_unreachable("function definition after = not 'delete' or 'default'");
87     }
88 
89     if (Tok.is(tok::comma)) {
90       Diag(KWLoc, diag::err_default_delete_in_multiple_declaration)
91         << Delete;
92       SkipUntil(tok::semi);
93     } else if (ExpectAndConsume(tok::semi, diag::err_expected_after,
94                                 Delete ? "delete" : "default")) {
95       SkipUntil(tok::semi);
96     }
97 
98     return FnD;
99   }
100 
101   // In delayed template parsing mode, if we are within a class template
102   // or if we are about to parse function member template then consume
103   // the tokens and store them for parsing at the end of the translation unit.
104   if (getLangOpts().DelayedTemplateParsing &&
105       DefinitionKind == FDK_Definition &&
106       !D.getDeclSpec().isConstexprSpecified() &&
107       !(FnD && FnD->getAsFunction() &&
108         FnD->getAsFunction()->getReturnType()->getContainedAutoType()) &&
109       ((Actions.CurContext->isDependentContext() ||
110         (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate &&
111          TemplateInfo.Kind != ParsedTemplateInfo::ExplicitSpecialization)) &&
112        !Actions.IsInsideALocalClassWithinATemplateFunction())) {
113 
114     CachedTokens Toks;
115     LexTemplateFunctionForLateParsing(Toks);
116 
117     if (FnD) {
118       FunctionDecl *FD = FnD->getAsFunction();
119       Actions.CheckForFunctionRedefinition(FD);
120       Actions.MarkAsLateParsedTemplate(FD, FnD, Toks);
121     }
122 
123     return FnD;
124   }
125 
126   // Consume the tokens and store them for later parsing.
127 
128   LexedMethod* LM = new LexedMethod(this, FnD);
129   getCurrentClass().LateParsedDeclarations.push_back(LM);
130   LM->TemplateScope = getCurScope()->isTemplateParamScope();
131   CachedTokens &Toks = LM->Toks;
132 
133   tok::TokenKind kind = Tok.getKind();
134   // Consume everything up to (and including) the left brace of the
135   // function body.
136   if (ConsumeAndStoreFunctionPrologue(Toks)) {
137     // We didn't find the left-brace we expected after the
138     // constructor initializer; we already printed an error, and it's likely
139     // impossible to recover, so don't try to parse this method later.
140     // Skip over the rest of the decl and back to somewhere that looks
141     // reasonable.
142     SkipMalformedDecl();
143     delete getCurrentClass().LateParsedDeclarations.back();
144     getCurrentClass().LateParsedDeclarations.pop_back();
145     return FnD;
146   } else {
147     // Consume everything up to (and including) the matching right brace.
148     ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false);
149   }
150 
151   // If we're in a function-try-block, we need to store all the catch blocks.
152   if (kind == tok::kw_try) {
153     while (Tok.is(tok::kw_catch)) {
154       ConsumeAndStoreUntil(tok::l_brace, Toks, /*StopAtSemi=*/false);
155       ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false);
156     }
157   }
158 
159   if (FnD) {
160     // If this is a friend function, mark that it's late-parsed so that
161     // it's still known to be a definition even before we attach the
162     // parsed body.  Sema needs to treat friend function definitions
163     // differently during template instantiation, and it's possible for
164     // the containing class to be instantiated before all its member
165     // function definitions are parsed.
166     //
167     // If you remove this, you can remove the code that clears the flag
168     // after parsing the member.
169     if (D.getDeclSpec().isFriendSpecified()) {
170       FunctionDecl *FD = FnD->getAsFunction();
171       Actions.CheckForFunctionRedefinition(FD);
172       FD->setLateTemplateParsed(true);
173     }
174   } else {
175     // If semantic analysis could not build a function declaration,
176     // just throw away the late-parsed declaration.
177     delete getCurrentClass().LateParsedDeclarations.back();
178     getCurrentClass().LateParsedDeclarations.pop_back();
179   }
180 
181   return FnD;
182 }
183 
184 /// ParseCXXNonStaticMemberInitializer - We parsed and verified that the
185 /// specified Declarator is a well formed C++ non-static data member
186 /// declaration. Now lex its initializer and store its tokens for parsing
187 /// after the class is complete.
188 void Parser::ParseCXXNonStaticMemberInitializer(Decl *VarD) {
189   assert((Tok.is(tok::l_brace) || Tok.is(tok::equal)) &&
190          "Current token not a '{' or '='!");
191 
192   LateParsedMemberInitializer *MI =
193     new LateParsedMemberInitializer(this, VarD);
194   getCurrentClass().LateParsedDeclarations.push_back(MI);
195   CachedTokens &Toks = MI->Toks;
196 
197   tok::TokenKind kind = Tok.getKind();
198   if (kind == tok::equal) {
199     Toks.push_back(Tok);
200     ConsumeToken();
201   }
202 
203   if (kind == tok::l_brace) {
204     // Begin by storing the '{' token.
205     Toks.push_back(Tok);
206     ConsumeBrace();
207 
208     // Consume everything up to (and including) the matching right brace.
209     ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/true);
210   } else {
211     // Consume everything up to (but excluding) the comma or semicolon.
212     ConsumeAndStoreInitializer(Toks, CIK_DefaultInitializer);
213   }
214 
215   // Store an artificial EOF token to ensure that we don't run off the end of
216   // the initializer when we come to parse it.
217   Token Eof;
218   Eof.startToken();
219   Eof.setKind(tok::eof);
220   Eof.setLocation(Tok.getLocation());
221   Eof.setEofData(VarD);
222   Toks.push_back(Eof);
223 }
224 
225 Parser::LateParsedDeclaration::~LateParsedDeclaration() {}
226 void Parser::LateParsedDeclaration::ParseLexedMethodDeclarations() {}
227 void Parser::LateParsedDeclaration::ParseLexedMemberInitializers() {}
228 void Parser::LateParsedDeclaration::ParseLexedMethodDefs() {}
229 
230 Parser::LateParsedClass::LateParsedClass(Parser *P, ParsingClass *C)
231   : Self(P), Class(C) {}
232 
233 Parser::LateParsedClass::~LateParsedClass() {
234   Self->DeallocateParsedClasses(Class);
235 }
236 
237 void Parser::LateParsedClass::ParseLexedMethodDeclarations() {
238   Self->ParseLexedMethodDeclarations(*Class);
239 }
240 
241 void Parser::LateParsedClass::ParseLexedMemberInitializers() {
242   Self->ParseLexedMemberInitializers(*Class);
243 }
244 
245 void Parser::LateParsedClass::ParseLexedMethodDefs() {
246   Self->ParseLexedMethodDefs(*Class);
247 }
248 
249 void Parser::LateParsedMethodDeclaration::ParseLexedMethodDeclarations() {
250   Self->ParseLexedMethodDeclaration(*this);
251 }
252 
253 void Parser::LexedMethod::ParseLexedMethodDefs() {
254   Self->ParseLexedMethodDef(*this);
255 }
256 
257 void Parser::LateParsedMemberInitializer::ParseLexedMemberInitializers() {
258   Self->ParseLexedMemberInitializer(*this);
259 }
260 
261 /// ParseLexedMethodDeclarations - We finished parsing the member
262 /// specification of a top (non-nested) C++ class. Now go over the
263 /// stack of method declarations with some parts for which parsing was
264 /// delayed (such as default arguments) and parse them.
265 void Parser::ParseLexedMethodDeclarations(ParsingClass &Class) {
266   bool HasTemplateScope = !Class.TopLevelClass && Class.TemplateScope;
267   ParseScope ClassTemplateScope(this, Scope::TemplateParamScope,
268                                 HasTemplateScope);
269   TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
270   if (HasTemplateScope) {
271     Actions.ActOnReenterTemplateScope(getCurScope(), Class.TagOrTemplate);
272     ++CurTemplateDepthTracker;
273   }
274 
275   // The current scope is still active if we're the top-level class.
276   // Otherwise we'll need to push and enter a new scope.
277   bool HasClassScope = !Class.TopLevelClass;
278   ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope,
279                         HasClassScope);
280   if (HasClassScope)
281     Actions.ActOnStartDelayedMemberDeclarations(getCurScope(),
282                                                 Class.TagOrTemplate);
283 
284   for (size_t i = 0; i < Class.LateParsedDeclarations.size(); ++i) {
285     Class.LateParsedDeclarations[i]->ParseLexedMethodDeclarations();
286   }
287 
288   if (HasClassScope)
289     Actions.ActOnFinishDelayedMemberDeclarations(getCurScope(),
290                                                  Class.TagOrTemplate);
291 }
292 
293 void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) {
294   // If this is a member template, introduce the template parameter scope.
295   ParseScope TemplateScope(this, Scope::TemplateParamScope, LM.TemplateScope);
296   TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
297   if (LM.TemplateScope) {
298     Actions.ActOnReenterTemplateScope(getCurScope(), LM.Method);
299     ++CurTemplateDepthTracker;
300   }
301   // Start the delayed C++ method declaration
302   Actions.ActOnStartDelayedCXXMethodDeclaration(getCurScope(), LM.Method);
303 
304   // Introduce the parameters into scope and parse their default
305   // arguments.
306   ParseScope PrototypeScope(this, Scope::FunctionPrototypeScope |
307                             Scope::FunctionDeclarationScope | Scope::DeclScope);
308   for (unsigned I = 0, N = LM.DefaultArgs.size(); I != N; ++I) {
309     // Introduce the parameter into scope.
310     Actions.ActOnDelayedCXXMethodParameter(getCurScope(),
311                                            LM.DefaultArgs[I].Param);
312 
313     if (CachedTokens *Toks = LM.DefaultArgs[I].Toks) {
314       // Save the current token position.
315       SourceLocation origLoc = Tok.getLocation();
316 
317       // Parse the default argument from its saved token stream.
318       Toks->push_back(Tok); // So that the current token doesn't get lost
319       PP.EnterTokenStream(&Toks->front(), Toks->size(), true, false);
320 
321       // Consume the previously-pushed token.
322       ConsumeAnyToken();
323 
324       // Consume the '='.
325       assert(Tok.is(tok::equal) && "Default argument not starting with '='");
326       SourceLocation EqualLoc = ConsumeToken();
327 
328       // The argument isn't actually potentially evaluated unless it is
329       // used.
330       EnterExpressionEvaluationContext Eval(Actions,
331                                             Sema::PotentiallyEvaluatedIfUsed,
332                                             LM.DefaultArgs[I].Param);
333 
334       ExprResult DefArgResult;
335       if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) {
336         Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
337         DefArgResult = ParseBraceInitializer();
338       } else
339         DefArgResult = ParseAssignmentExpression();
340       DefArgResult = Actions.CorrectDelayedTyposInExpr(DefArgResult);
341       if (DefArgResult.isInvalid())
342         Actions.ActOnParamDefaultArgumentError(LM.DefaultArgs[I].Param,
343                                                EqualLoc);
344       else {
345         if (!TryConsumeToken(tok::cxx_defaultarg_end)) {
346           // The last two tokens are the terminator and the saved value of
347           // Tok; the last token in the default argument is the one before
348           // those.
349           assert(Toks->size() >= 3 && "expected a token in default arg");
350           Diag(Tok.getLocation(), diag::err_default_arg_unparsed)
351             << SourceRange(Tok.getLocation(),
352                            (*Toks)[Toks->size() - 3].getLocation());
353         }
354         Actions.ActOnParamDefaultArgument(LM.DefaultArgs[I].Param, EqualLoc,
355                                           DefArgResult.get());
356       }
357 
358       assert(!PP.getSourceManager().isBeforeInTranslationUnit(origLoc,
359                                                          Tok.getLocation()) &&
360              "ParseAssignmentExpression went over the default arg tokens!");
361       // There could be leftover tokens (e.g. because of an error).
362       // Skip through until we reach the original token position.
363       while (Tok.getLocation() != origLoc && Tok.isNot(tok::eof))
364         ConsumeAnyToken();
365 
366       delete Toks;
367       LM.DefaultArgs[I].Toks = nullptr;
368     }
369   }
370 
371   // Parse a delayed exception-specification, if there is one.
372   if (CachedTokens *Toks = LM.ExceptionSpecTokens) {
373     // Save the current token position.
374     SourceLocation origLoc = Tok.getLocation();
375 
376     // Parse the default argument from its saved token stream.
377     Toks->push_back(Tok); // So that the current token doesn't get lost
378     PP.EnterTokenStream(&Toks->front(), Toks->size(), true, false);
379 
380     // Consume the previously-pushed token.
381     ConsumeAnyToken();
382 
383     // C++11 [expr.prim.general]p3:
384     //   If a declaration declares a member function or member function
385     //   template of a class X, the expression this is a prvalue of type
386     //   "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
387     //   and the end of the function-definition, member-declarator, or
388     //   declarator.
389     CXXMethodDecl *Method;
390     if (FunctionTemplateDecl *FunTmpl
391           = dyn_cast<FunctionTemplateDecl>(LM.Method))
392       Method = cast<CXXMethodDecl>(FunTmpl->getTemplatedDecl());
393     else
394       Method = cast<CXXMethodDecl>(LM.Method);
395 
396     Sema::CXXThisScopeRAII ThisScope(Actions, Method->getParent(),
397                                      Method->getTypeQualifiers(),
398                                      getLangOpts().CPlusPlus11);
399 
400     // Parse the exception-specification.
401     SourceRange SpecificationRange;
402     SmallVector<ParsedType, 4> DynamicExceptions;
403     SmallVector<SourceRange, 4> DynamicExceptionRanges;
404     ExprResult NoexceptExpr;
405     CachedTokens *ExceptionSpecTokens;
406 
407     ExceptionSpecificationType EST
408       = tryParseExceptionSpecification(/*Delayed=*/false, SpecificationRange,
409                                        DynamicExceptions,
410                                        DynamicExceptionRanges, NoexceptExpr,
411                                        ExceptionSpecTokens);
412 
413     // Clean up the remaining tokens.
414     if (Tok.is(tok::cxx_exceptspec_end))
415       ConsumeToken();
416     else if (EST != EST_None)
417       Diag(Tok.getLocation(), diag::err_except_spec_unparsed);
418 
419     // Attach the exception-specification to the method.
420     Actions.actOnDelayedExceptionSpecification(LM.Method, EST,
421                                                SpecificationRange,
422                                                DynamicExceptions,
423                                                DynamicExceptionRanges,
424                                                NoexceptExpr.isUsable()?
425                                                  NoexceptExpr.get() : nullptr);
426 
427     assert(!PP.getSourceManager().isBeforeInTranslationUnit(origLoc,
428                                                             Tok.getLocation()) &&
429            "tryParseExceptionSpecification went over the exception tokens!");
430 
431     // There could be leftover tokens (e.g. because of an error).
432     // Skip through until we reach the original token position.
433     while (Tok.getLocation() != origLoc && Tok.isNot(tok::eof))
434       ConsumeAnyToken();
435 
436     delete Toks;
437     LM.ExceptionSpecTokens = nullptr;
438   }
439 
440   PrototypeScope.Exit();
441 
442   // Finish the delayed C++ method declaration.
443   Actions.ActOnFinishDelayedCXXMethodDeclaration(getCurScope(), LM.Method);
444 }
445 
446 /// ParseLexedMethodDefs - We finished parsing the member specification of a top
447 /// (non-nested) C++ class. Now go over the stack of lexed methods that were
448 /// collected during its parsing and parse them all.
449 void Parser::ParseLexedMethodDefs(ParsingClass &Class) {
450   bool HasTemplateScope = !Class.TopLevelClass && Class.TemplateScope;
451   ParseScope ClassTemplateScope(this, Scope::TemplateParamScope, HasTemplateScope);
452   TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
453   if (HasTemplateScope) {
454     Actions.ActOnReenterTemplateScope(getCurScope(), Class.TagOrTemplate);
455     ++CurTemplateDepthTracker;
456   }
457   bool HasClassScope = !Class.TopLevelClass;
458   ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope,
459                         HasClassScope);
460 
461   for (size_t i = 0; i < Class.LateParsedDeclarations.size(); ++i) {
462     Class.LateParsedDeclarations[i]->ParseLexedMethodDefs();
463   }
464 }
465 
466 void Parser::ParseLexedMethodDef(LexedMethod &LM) {
467   // If this is a member template, introduce the template parameter scope.
468   ParseScope TemplateScope(this, Scope::TemplateParamScope, LM.TemplateScope);
469   TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
470   if (LM.TemplateScope) {
471     Actions.ActOnReenterTemplateScope(getCurScope(), LM.D);
472     ++CurTemplateDepthTracker;
473   }
474   // Save the current token position.
475   SourceLocation origLoc = Tok.getLocation();
476 
477   assert(!LM.Toks.empty() && "Empty body!");
478   // Append the current token at the end of the new token stream so that it
479   // doesn't get lost.
480   LM.Toks.push_back(Tok);
481   PP.EnterTokenStream(LM.Toks.data(), LM.Toks.size(), true, false);
482 
483   // Consume the previously pushed token.
484   ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
485   assert((Tok.is(tok::l_brace) || Tok.is(tok::colon) || Tok.is(tok::kw_try))
486          && "Inline method not starting with '{', ':' or 'try'");
487 
488   // Parse the method body. Function body parsing code is similar enough
489   // to be re-used for method bodies as well.
490   ParseScope FnScope(this, Scope::FnScope|Scope::DeclScope);
491   Actions.ActOnStartOfFunctionDef(getCurScope(), LM.D);
492 
493   if (Tok.is(tok::kw_try)) {
494     ParseFunctionTryBlock(LM.D, FnScope);
495     assert(!PP.getSourceManager().isBeforeInTranslationUnit(origLoc,
496                                                          Tok.getLocation()) &&
497            "ParseFunctionTryBlock went over the cached tokens!");
498     // There could be leftover tokens (e.g. because of an error).
499     // Skip through until we reach the original token position.
500     while (Tok.getLocation() != origLoc && Tok.isNot(tok::eof))
501       ConsumeAnyToken();
502     return;
503   }
504   if (Tok.is(tok::colon)) {
505     ParseConstructorInitializer(LM.D);
506 
507     // Error recovery.
508     if (!Tok.is(tok::l_brace)) {
509       FnScope.Exit();
510       Actions.ActOnFinishFunctionBody(LM.D, nullptr);
511       while (Tok.getLocation() != origLoc && Tok.isNot(tok::eof))
512         ConsumeAnyToken();
513       return;
514     }
515   } else
516     Actions.ActOnDefaultCtorInitializers(LM.D);
517 
518   assert((Actions.getDiagnostics().hasErrorOccurred() ||
519           !isa<FunctionTemplateDecl>(LM.D) ||
520           cast<FunctionTemplateDecl>(LM.D)->getTemplateParameters()->getDepth()
521             < TemplateParameterDepth) &&
522          "TemplateParameterDepth should be greater than the depth of "
523          "current template being instantiated!");
524 
525   ParseFunctionStatementBody(LM.D, FnScope);
526 
527   // Clear the late-template-parsed bit if we set it before.
528   if (LM.D)
529     LM.D->getAsFunction()->setLateTemplateParsed(false);
530 
531   if (Tok.getLocation() != origLoc) {
532     // Due to parsing error, we either went over the cached tokens or
533     // there are still cached tokens left. If it's the latter case skip the
534     // leftover tokens.
535     // Since this is an uncommon situation that should be avoided, use the
536     // expensive isBeforeInTranslationUnit call.
537     if (PP.getSourceManager().isBeforeInTranslationUnit(Tok.getLocation(),
538                                                         origLoc))
539       while (Tok.getLocation() != origLoc && Tok.isNot(tok::eof))
540         ConsumeAnyToken();
541   }
542 
543   if (CXXMethodDecl *MD = dyn_cast_or_null<CXXMethodDecl>(LM.D))
544     Actions.ActOnFinishInlineMethodDef(MD);
545 }
546 
547 /// ParseLexedMemberInitializers - We finished parsing the member specification
548 /// of a top (non-nested) C++ class. Now go over the stack of lexed data member
549 /// initializers that were collected during its parsing and parse them all.
550 void Parser::ParseLexedMemberInitializers(ParsingClass &Class) {
551   bool HasTemplateScope = !Class.TopLevelClass && Class.TemplateScope;
552   ParseScope ClassTemplateScope(this, Scope::TemplateParamScope,
553                                 HasTemplateScope);
554   TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
555   if (HasTemplateScope) {
556     Actions.ActOnReenterTemplateScope(getCurScope(), Class.TagOrTemplate);
557     ++CurTemplateDepthTracker;
558   }
559   // Set or update the scope flags.
560   bool AlreadyHasClassScope = Class.TopLevelClass;
561   unsigned ScopeFlags = Scope::ClassScope|Scope::DeclScope;
562   ParseScope ClassScope(this, ScopeFlags, !AlreadyHasClassScope);
563   ParseScopeFlags ClassScopeFlags(this, ScopeFlags, AlreadyHasClassScope);
564 
565   if (!AlreadyHasClassScope)
566     Actions.ActOnStartDelayedMemberDeclarations(getCurScope(),
567                                                 Class.TagOrTemplate);
568 
569   if (!Class.LateParsedDeclarations.empty()) {
570     // C++11 [expr.prim.general]p4:
571     //   Otherwise, if a member-declarator declares a non-static data member
572     //  (9.2) of a class X, the expression this is a prvalue of type "pointer
573     //  to X" within the optional brace-or-equal-initializer. It shall not
574     //  appear elsewhere in the member-declarator.
575     Sema::CXXThisScopeRAII ThisScope(Actions, Class.TagOrTemplate,
576                                      /*TypeQuals=*/(unsigned)0);
577 
578     for (size_t i = 0; i < Class.LateParsedDeclarations.size(); ++i) {
579       Class.LateParsedDeclarations[i]->ParseLexedMemberInitializers();
580     }
581   }
582 
583   if (!AlreadyHasClassScope)
584     Actions.ActOnFinishDelayedMemberDeclarations(getCurScope(),
585                                                  Class.TagOrTemplate);
586 
587   Actions.ActOnFinishDelayedMemberInitializers(Class.TagOrTemplate);
588 }
589 
590 void Parser::ParseLexedMemberInitializer(LateParsedMemberInitializer &MI) {
591   if (!MI.Field || MI.Field->isInvalidDecl())
592     return;
593 
594   // Append the current token at the end of the new token stream so that it
595   // doesn't get lost.
596   MI.Toks.push_back(Tok);
597   PP.EnterTokenStream(MI.Toks.data(), MI.Toks.size(), true, false);
598 
599   // Consume the previously pushed token.
600   ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
601 
602   SourceLocation EqualLoc;
603 
604   Actions.ActOnStartCXXInClassMemberInitializer();
605 
606   ExprResult Init = ParseCXXMemberInitializer(MI.Field, /*IsFunction=*/false,
607                                               EqualLoc);
608 
609   Actions.ActOnFinishCXXInClassMemberInitializer(MI.Field, EqualLoc,
610                                                  Init.get());
611 
612   // The next token should be our artificial terminating EOF token.
613   if (Tok.isNot(tok::eof)) {
614     if (!Init.isInvalid()) {
615       SourceLocation EndLoc = PP.getLocForEndOfToken(PrevTokLocation);
616       if (!EndLoc.isValid())
617         EndLoc = Tok.getLocation();
618       // No fixit; we can't recover as if there were a semicolon here.
619       Diag(EndLoc, diag::err_expected_semi_decl_list);
620     }
621 
622     // Consume tokens until we hit the artificial EOF.
623     while (Tok.isNot(tok::eof))
624       ConsumeAnyToken();
625   }
626   // Make sure this is *our* artificial EOF token.
627   if (Tok.getEofData() == MI.Field)
628     ConsumeAnyToken();
629 }
630 
631 /// ConsumeAndStoreUntil - Consume and store the token at the passed token
632 /// container until the token 'T' is reached (which gets
633 /// consumed/stored too, if ConsumeFinalToken).
634 /// If StopAtSemi is true, then we will stop early at a ';' character.
635 /// Returns true if token 'T1' or 'T2' was found.
636 /// NOTE: This is a specialized version of Parser::SkipUntil.
637 bool Parser::ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2,
638                                   CachedTokens &Toks,
639                                   bool StopAtSemi, bool ConsumeFinalToken) {
640   // We always want this function to consume at least one token if the first
641   // token isn't T and if not at EOF.
642   bool isFirstTokenConsumed = true;
643   while (1) {
644     // If we found one of the tokens, stop and return true.
645     if (Tok.is(T1) || Tok.is(T2)) {
646       if (ConsumeFinalToken) {
647         Toks.push_back(Tok);
648         ConsumeAnyToken();
649       }
650       return true;
651     }
652 
653     switch (Tok.getKind()) {
654     case tok::eof:
655     case tok::annot_module_begin:
656     case tok::annot_module_end:
657     case tok::annot_module_include:
658       // Ran out of tokens.
659       return false;
660 
661     case tok::l_paren:
662       // Recursively consume properly-nested parens.
663       Toks.push_back(Tok);
664       ConsumeParen();
665       ConsumeAndStoreUntil(tok::r_paren, Toks, /*StopAtSemi=*/false);
666       break;
667     case tok::l_square:
668       // Recursively consume properly-nested square brackets.
669       Toks.push_back(Tok);
670       ConsumeBracket();
671       ConsumeAndStoreUntil(tok::r_square, Toks, /*StopAtSemi=*/false);
672       break;
673     case tok::l_brace:
674       // Recursively consume properly-nested braces.
675       Toks.push_back(Tok);
676       ConsumeBrace();
677       ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false);
678       break;
679 
680     // Okay, we found a ']' or '}' or ')', which we think should be balanced.
681     // Since the user wasn't looking for this token (if they were, it would
682     // already be handled), this isn't balanced.  If there is a LHS token at a
683     // higher level, we will assume that this matches the unbalanced token
684     // and return it.  Otherwise, this is a spurious RHS token, which we skip.
685     case tok::r_paren:
686       if (ParenCount && !isFirstTokenConsumed)
687         return false;  // Matches something.
688       Toks.push_back(Tok);
689       ConsumeParen();
690       break;
691     case tok::r_square:
692       if (BracketCount && !isFirstTokenConsumed)
693         return false;  // Matches something.
694       Toks.push_back(Tok);
695       ConsumeBracket();
696       break;
697     case tok::r_brace:
698       if (BraceCount && !isFirstTokenConsumed)
699         return false;  // Matches something.
700       Toks.push_back(Tok);
701       ConsumeBrace();
702       break;
703 
704     case tok::code_completion:
705       Toks.push_back(Tok);
706       ConsumeCodeCompletionToken();
707       break;
708 
709     case tok::string_literal:
710     case tok::wide_string_literal:
711     case tok::utf8_string_literal:
712     case tok::utf16_string_literal:
713     case tok::utf32_string_literal:
714       Toks.push_back(Tok);
715       ConsumeStringToken();
716       break;
717     case tok::semi:
718       if (StopAtSemi)
719         return false;
720       // FALL THROUGH.
721     default:
722       // consume this token.
723       Toks.push_back(Tok);
724       ConsumeToken();
725       break;
726     }
727     isFirstTokenConsumed = false;
728   }
729 }
730 
731 /// \brief Consume tokens and store them in the passed token container until
732 /// we've passed the try keyword and constructor initializers and have consumed
733 /// the opening brace of the function body. The opening brace will be consumed
734 /// if and only if there was no error.
735 ///
736 /// \return True on error.
737 bool Parser::ConsumeAndStoreFunctionPrologue(CachedTokens &Toks) {
738   if (Tok.is(tok::kw_try)) {
739     Toks.push_back(Tok);
740     ConsumeToken();
741   }
742 
743   if (Tok.isNot(tok::colon)) {
744     // Easy case, just a function body.
745 
746     // Grab any remaining garbage to be diagnosed later. We stop when we reach a
747     // brace: an opening one is the function body, while a closing one probably
748     // means we've reached the end of the class.
749     ConsumeAndStoreUntil(tok::l_brace, tok::r_brace, Toks,
750                          /*StopAtSemi=*/true,
751                          /*ConsumeFinalToken=*/false);
752     if (Tok.isNot(tok::l_brace))
753       return Diag(Tok.getLocation(), diag::err_expected) << tok::l_brace;
754 
755     Toks.push_back(Tok);
756     ConsumeBrace();
757     return false;
758   }
759 
760   Toks.push_back(Tok);
761   ConsumeToken();
762 
763   // We can't reliably skip over a mem-initializer-id, because it could be
764   // a template-id involving not-yet-declared names. Given:
765   //
766   //   S ( ) : a < b < c > ( e )
767   //
768   // 'e' might be an initializer or part of a template argument, depending
769   // on whether 'b' is a template.
770 
771   // Track whether we might be inside a template argument. We can give
772   // significantly better diagnostics if we know that we're not.
773   bool MightBeTemplateArgument = false;
774 
775   while (true) {
776     // Skip over the mem-initializer-id, if possible.
777     if (Tok.is(tok::kw_decltype)) {
778       Toks.push_back(Tok);
779       SourceLocation OpenLoc = ConsumeToken();
780       if (Tok.isNot(tok::l_paren))
781         return Diag(Tok.getLocation(), diag::err_expected_lparen_after)
782                  << "decltype";
783       Toks.push_back(Tok);
784       ConsumeParen();
785       if (!ConsumeAndStoreUntil(tok::r_paren, Toks, /*StopAtSemi=*/true)) {
786         Diag(Tok.getLocation(), diag::err_expected) << tok::r_paren;
787         Diag(OpenLoc, diag::note_matching) << tok::l_paren;
788         return true;
789       }
790     }
791     do {
792       // Walk over a component of a nested-name-specifier.
793       if (Tok.is(tok::coloncolon)) {
794         Toks.push_back(Tok);
795         ConsumeToken();
796 
797         if (Tok.is(tok::kw_template)) {
798           Toks.push_back(Tok);
799           ConsumeToken();
800         }
801       }
802 
803       if (Tok.is(tok::identifier) || Tok.is(tok::kw_template)) {
804         Toks.push_back(Tok);
805         ConsumeToken();
806       } else if (Tok.is(tok::code_completion)) {
807         Toks.push_back(Tok);
808         ConsumeCodeCompletionToken();
809         // Consume the rest of the initializers permissively.
810         // FIXME: We should be able to perform code-completion here even if
811         //        there isn't a subsequent '{' token.
812         MightBeTemplateArgument = true;
813         break;
814       } else {
815         break;
816       }
817     } while (Tok.is(tok::coloncolon));
818 
819     if (Tok.is(tok::less))
820       MightBeTemplateArgument = true;
821 
822     if (MightBeTemplateArgument) {
823       // We may be inside a template argument list. Grab up to the start of the
824       // next parenthesized initializer or braced-init-list. This *might* be the
825       // initializer, or it might be a subexpression in the template argument
826       // list.
827       // FIXME: Count angle brackets, and clear MightBeTemplateArgument
828       //        if all angles are closed.
829       if (!ConsumeAndStoreUntil(tok::l_paren, tok::l_brace, Toks,
830                                 /*StopAtSemi=*/true,
831                                 /*ConsumeFinalToken=*/false)) {
832         // We're not just missing the initializer, we're also missing the
833         // function body!
834         return Diag(Tok.getLocation(), diag::err_expected) << tok::l_brace;
835       }
836     } else if (Tok.isNot(tok::l_paren) && Tok.isNot(tok::l_brace)) {
837       // We found something weird in a mem-initializer-id.
838       if (getLangOpts().CPlusPlus11)
839         return Diag(Tok.getLocation(), diag::err_expected_either)
840                << tok::l_paren << tok::l_brace;
841       else
842         return Diag(Tok.getLocation(), diag::err_expected) << tok::l_paren;
843     }
844 
845     tok::TokenKind kind = Tok.getKind();
846     Toks.push_back(Tok);
847     bool IsLParen = (kind == tok::l_paren);
848     SourceLocation OpenLoc = Tok.getLocation();
849 
850     if (IsLParen) {
851       ConsumeParen();
852     } else {
853       assert(kind == tok::l_brace && "Must be left paren or brace here.");
854       ConsumeBrace();
855       // In C++03, this has to be the start of the function body, which
856       // means the initializer is malformed; we'll diagnose it later.
857       if (!getLangOpts().CPlusPlus11)
858         return false;
859     }
860 
861     // Grab the initializer (or the subexpression of the template argument).
862     // FIXME: If we support lambdas here, we'll need to set StopAtSemi to false
863     //        if we might be inside the braces of a lambda-expression.
864     tok::TokenKind CloseKind = IsLParen ? tok::r_paren : tok::r_brace;
865     if (!ConsumeAndStoreUntil(CloseKind, Toks, /*StopAtSemi=*/true)) {
866       Diag(Tok, diag::err_expected) << CloseKind;
867       Diag(OpenLoc, diag::note_matching) << kind;
868       return true;
869     }
870 
871     // Grab pack ellipsis, if present.
872     if (Tok.is(tok::ellipsis)) {
873       Toks.push_back(Tok);
874       ConsumeToken();
875     }
876 
877     // If we know we just consumed a mem-initializer, we must have ',' or '{'
878     // next.
879     if (Tok.is(tok::comma)) {
880       Toks.push_back(Tok);
881       ConsumeToken();
882     } else if (Tok.is(tok::l_brace)) {
883       // This is the function body if the ')' or '}' is immediately followed by
884       // a '{'. That cannot happen within a template argument, apart from the
885       // case where a template argument contains a compound literal:
886       //
887       //   S ( ) : a < b < c > ( d ) { }
888       //   // End of declaration, or still inside the template argument?
889       //
890       // ... and the case where the template argument contains a lambda:
891       //
892       //   S ( ) : a < 0 && b < c > ( d ) + [ ] ( ) { return 0; }
893       //     ( ) > ( ) { }
894       //
895       // FIXME: Disambiguate these cases. Note that the latter case is probably
896       //        going to be made ill-formed by core issue 1607.
897       Toks.push_back(Tok);
898       ConsumeBrace();
899       return false;
900     } else if (!MightBeTemplateArgument) {
901       return Diag(Tok.getLocation(), diag::err_expected_either) << tok::l_brace
902                                                                 << tok::comma;
903     }
904   }
905 }
906 
907 /// \brief Consume and store tokens from the '?' to the ':' in a conditional
908 /// expression.
909 bool Parser::ConsumeAndStoreConditional(CachedTokens &Toks) {
910   // Consume '?'.
911   assert(Tok.is(tok::question));
912   Toks.push_back(Tok);
913   ConsumeToken();
914 
915   while (Tok.isNot(tok::colon)) {
916     if (!ConsumeAndStoreUntil(tok::question, tok::colon, Toks,
917                               /*StopAtSemi=*/true,
918                               /*ConsumeFinalToken=*/false))
919       return false;
920 
921     // If we found a nested conditional, consume it.
922     if (Tok.is(tok::question) && !ConsumeAndStoreConditional(Toks))
923       return false;
924   }
925 
926   // Consume ':'.
927   Toks.push_back(Tok);
928   ConsumeToken();
929   return true;
930 }
931 
932 /// \brief A tentative parsing action that can also revert token annotations.
933 class Parser::UnannotatedTentativeParsingAction : public TentativeParsingAction {
934 public:
935   explicit UnannotatedTentativeParsingAction(Parser &Self,
936                                              tok::TokenKind EndKind)
937       : TentativeParsingAction(Self), Self(Self), EndKind(EndKind) {
938     // Stash away the old token stream, so we can restore it once the
939     // tentative parse is complete.
940     TentativeParsingAction Inner(Self);
941     Self.ConsumeAndStoreUntil(EndKind, Toks, true, /*ConsumeFinalToken*/false);
942     Inner.Revert();
943   }
944 
945   void RevertAnnotations() {
946     Revert();
947 
948     // Put back the original tokens.
949     Self.SkipUntil(EndKind, StopAtSemi | StopBeforeMatch);
950     if (Toks.size()) {
951       Token *Buffer = new Token[Toks.size()];
952       std::copy(Toks.begin() + 1, Toks.end(), Buffer);
953       Buffer[Toks.size() - 1] = Self.Tok;
954       Self.PP.EnterTokenStream(Buffer, Toks.size(), true, /*Owned*/true);
955 
956       Self.Tok = Toks.front();
957     }
958   }
959 
960 private:
961   Parser &Self;
962   CachedTokens Toks;
963   tok::TokenKind EndKind;
964 };
965 
966 /// ConsumeAndStoreInitializer - Consume and store the token at the passed token
967 /// container until the end of the current initializer expression (either a
968 /// default argument or an in-class initializer for a non-static data member).
969 ///
970 /// Returns \c true if we reached the end of something initializer-shaped,
971 /// \c false if we bailed out.
972 bool Parser::ConsumeAndStoreInitializer(CachedTokens &Toks,
973                                         CachedInitKind CIK) {
974   // We always want this function to consume at least one token if not at EOF.
975   bool IsFirstToken = true;
976 
977   // Number of possible unclosed <s we've seen so far. These might be templates,
978   // and might not, but if there were none of them (or we know for sure that
979   // we're within a template), we can avoid a tentative parse.
980   unsigned AngleCount = 0;
981   unsigned KnownTemplateCount = 0;
982 
983   while (1) {
984     switch (Tok.getKind()) {
985     case tok::comma:
986       // If we might be in a template, perform a tentative parse to check.
987       if (!AngleCount)
988         // Not a template argument: this is the end of the initializer.
989         return true;
990       if (KnownTemplateCount)
991         goto consume_token;
992 
993       // We hit a comma inside angle brackets. This is the hard case. The
994       // rule we follow is:
995       //  * For a default argument, if the tokens after the comma form a
996       //    syntactically-valid parameter-declaration-clause, in which each
997       //    parameter has an initializer, then this comma ends the default
998       //    argument.
999       //  * For a default initializer, if the tokens after the comma form a
1000       //    syntactically-valid init-declarator-list, then this comma ends
1001       //    the default initializer.
1002       {
1003         UnannotatedTentativeParsingAction PA(*this,
1004                                              CIK == CIK_DefaultInitializer
1005                                                ? tok::semi : tok::r_paren);
1006         Sema::TentativeAnalysisScope Scope(Actions);
1007 
1008         TPResult Result = TPResult::Error;
1009         ConsumeToken();
1010         switch (CIK) {
1011         case CIK_DefaultInitializer:
1012           Result = TryParseInitDeclaratorList();
1013           // If we parsed a complete, ambiguous init-declarator-list, this
1014           // is only syntactically-valid if it's followed by a semicolon.
1015           if (Result == TPResult::Ambiguous && Tok.isNot(tok::semi))
1016             Result = TPResult::False;
1017           break;
1018 
1019         case CIK_DefaultArgument:
1020           bool InvalidAsDeclaration = false;
1021           Result = TryParseParameterDeclarationClause(
1022               &InvalidAsDeclaration, /*VersusTemplateArgument*/true);
1023           // If this is an expression or a declaration with a missing
1024           // 'typename', assume it's not a declaration.
1025           if (Result == TPResult::Ambiguous && InvalidAsDeclaration)
1026             Result = TPResult::False;
1027           break;
1028         }
1029 
1030         // If what follows could be a declaration, it is a declaration.
1031         if (Result != TPResult::False && Result != TPResult::Error) {
1032           PA.Revert();
1033           return true;
1034         }
1035 
1036         // In the uncommon case that we decide the following tokens are part
1037         // of a template argument, revert any annotations we've performed in
1038         // those tokens. We're not going to look them up until we've parsed
1039         // the rest of the class, and that might add more declarations.
1040         PA.RevertAnnotations();
1041       }
1042 
1043       // Keep going. We know we're inside a template argument list now.
1044       ++KnownTemplateCount;
1045       goto consume_token;
1046 
1047     case tok::eof:
1048     case tok::annot_module_begin:
1049     case tok::annot_module_end:
1050     case tok::annot_module_include:
1051       // Ran out of tokens.
1052       return false;
1053 
1054     case tok::less:
1055       // FIXME: A '<' can only start a template-id if it's preceded by an
1056       // identifier, an operator-function-id, or a literal-operator-id.
1057       ++AngleCount;
1058       goto consume_token;
1059 
1060     case tok::question:
1061       // In 'a ? b : c', 'b' can contain an unparenthesized comma. If it does,
1062       // that is *never* the end of the initializer. Skip to the ':'.
1063       if (!ConsumeAndStoreConditional(Toks))
1064         return false;
1065       break;
1066 
1067     case tok::greatergreatergreater:
1068       if (!getLangOpts().CPlusPlus11)
1069         goto consume_token;
1070       if (AngleCount) --AngleCount;
1071       if (KnownTemplateCount) --KnownTemplateCount;
1072       // Fall through.
1073     case tok::greatergreater:
1074       if (!getLangOpts().CPlusPlus11)
1075         goto consume_token;
1076       if (AngleCount) --AngleCount;
1077       if (KnownTemplateCount) --KnownTemplateCount;
1078       // Fall through.
1079     case tok::greater:
1080       if (AngleCount) --AngleCount;
1081       if (KnownTemplateCount) --KnownTemplateCount;
1082       goto consume_token;
1083 
1084     case tok::kw_template:
1085       // 'template' identifier '<' is known to start a template argument list,
1086       // and can be used to disambiguate the parse.
1087       // FIXME: Support all forms of 'template' unqualified-id '<'.
1088       Toks.push_back(Tok);
1089       ConsumeToken();
1090       if (Tok.is(tok::identifier)) {
1091         Toks.push_back(Tok);
1092         ConsumeToken();
1093         if (Tok.is(tok::less)) {
1094           ++AngleCount;
1095           ++KnownTemplateCount;
1096           Toks.push_back(Tok);
1097           ConsumeToken();
1098         }
1099       }
1100       break;
1101 
1102     case tok::kw_operator:
1103       // If 'operator' precedes other punctuation, that punctuation loses
1104       // its special behavior.
1105       Toks.push_back(Tok);
1106       ConsumeToken();
1107       switch (Tok.getKind()) {
1108       case tok::comma:
1109       case tok::greatergreatergreater:
1110       case tok::greatergreater:
1111       case tok::greater:
1112       case tok::less:
1113         Toks.push_back(Tok);
1114         ConsumeToken();
1115         break;
1116       default:
1117         break;
1118       }
1119       break;
1120 
1121     case tok::l_paren:
1122       // Recursively consume properly-nested parens.
1123       Toks.push_back(Tok);
1124       ConsumeParen();
1125       ConsumeAndStoreUntil(tok::r_paren, Toks, /*StopAtSemi=*/false);
1126       break;
1127     case tok::l_square:
1128       // Recursively consume properly-nested square brackets.
1129       Toks.push_back(Tok);
1130       ConsumeBracket();
1131       ConsumeAndStoreUntil(tok::r_square, Toks, /*StopAtSemi=*/false);
1132       break;
1133     case tok::l_brace:
1134       // Recursively consume properly-nested braces.
1135       Toks.push_back(Tok);
1136       ConsumeBrace();
1137       ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false);
1138       break;
1139 
1140     // Okay, we found a ']' or '}' or ')', which we think should be balanced.
1141     // Since the user wasn't looking for this token (if they were, it would
1142     // already be handled), this isn't balanced.  If there is a LHS token at a
1143     // higher level, we will assume that this matches the unbalanced token
1144     // and return it.  Otherwise, this is a spurious RHS token, which we
1145     // consume and pass on to downstream code to diagnose.
1146     case tok::r_paren:
1147       if (CIK == CIK_DefaultArgument)
1148         return true; // End of the default argument.
1149       if (ParenCount && !IsFirstToken)
1150         return false;
1151       Toks.push_back(Tok);
1152       ConsumeParen();
1153       continue;
1154     case tok::r_square:
1155       if (BracketCount && !IsFirstToken)
1156         return false;
1157       Toks.push_back(Tok);
1158       ConsumeBracket();
1159       continue;
1160     case tok::r_brace:
1161       if (BraceCount && !IsFirstToken)
1162         return false;
1163       Toks.push_back(Tok);
1164       ConsumeBrace();
1165       continue;
1166 
1167     case tok::code_completion:
1168       Toks.push_back(Tok);
1169       ConsumeCodeCompletionToken();
1170       break;
1171 
1172     case tok::string_literal:
1173     case tok::wide_string_literal:
1174     case tok::utf8_string_literal:
1175     case tok::utf16_string_literal:
1176     case tok::utf32_string_literal:
1177       Toks.push_back(Tok);
1178       ConsumeStringToken();
1179       break;
1180     case tok::semi:
1181       if (CIK == CIK_DefaultInitializer)
1182         return true; // End of the default initializer.
1183       // FALL THROUGH.
1184     default:
1185     consume_token:
1186       Toks.push_back(Tok);
1187       ConsumeToken();
1188       break;
1189     }
1190     IsFirstToken = false;
1191   }
1192 }
1193