ParseCXXInlineMethods.cpp 41 KB

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