blob: baba90840fd2cdd005020fa4737c38b546ccb494 [file] [log] [blame]
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +00001//===--- 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"
Chandler Carruth3a022472012-12-04 09:13:33 +000015#include "RAIIObjectsForParser.h"
16#include "clang/AST/DeclTemplate.h"
17#include "clang/Parse/ParseDiagnostic.h"
John McCall8b0666c2010-08-20 18:27:03 +000018#include "clang/Sema/DeclSpec.h"
19#include "clang/Sema/Scope.h"
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +000020using namespace clang;
21
John McCalle68672f2013-03-14 05:13:41 +000022/// Get the FunctionDecl for a function or function template decl.
23static FunctionDecl *getFunctionDecl(Decl *D) {
24 if (FunctionDecl *fn = dyn_cast<FunctionDecl>(D))
25 return fn;
26 return cast<FunctionTemplateDecl>(D)->getTemplatedDecl();
27}
28
Sebastian Redla7b98a72009-04-26 20:35:05 +000029/// ParseCXXInlineMethodDef - We parsed and verified that the specified
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +000030/// Declarator is a well formed C++ inline method definition. Now lex its body
31/// and store its tokens for parsing after the C++ class is complete.
Rafael Espindolac2453dd2013-01-08 21:00:12 +000032NamedDecl *Parser::ParseCXXInlineMethodDef(AccessSpecifier AS,
Erik Verbruggenca98f2a2011-10-13 09:41:32 +000033 AttributeList *AccessAttrs,
34 ParsingDeclarator &D,
Douglas Gregor5d1b4e32011-11-07 20:56:01 +000035 const ParsedTemplateInfo &TemplateInfo,
36 const VirtSpecifiers& VS,
37 FunctionDefinitionKind DefinitionKind,
38 ExprResult& Init) {
Abramo Bagnara924a8f32010-12-10 16:29:40 +000039 assert(D.isFunctionDeclarator() && "This isn't a function declarator!");
Alexis Hunt5a7fa252011-05-12 06:15:49 +000040 assert((Tok.is(tok::l_brace) || Tok.is(tok::colon) || Tok.is(tok::kw_try) ||
41 Tok.is(tok::equal)) &&
42 "Current token not a '{', ':', '=', or 'try'!");
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +000043
Benjamin Kramercc4c49d2012-08-23 23:38:35 +000044 MultiTemplateParamsArg TemplateParams(
Alexis Hunt1deb9722010-04-14 23:07:37 +000045 TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->data() : 0,
46 TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->size() : 0);
47
Rafael Espindolac2453dd2013-01-08 21:00:12 +000048 NamedDecl *FnD;
Douglas Gregor5d1b4e32011-11-07 20:56:01 +000049 D.setFunctionDefinitionKind(DefinitionKind);
John McCall07e91c02009-08-06 02:15:43 +000050 if (D.getDeclSpec().isFriendSpecified())
Kaelyn Uhrain4dc695d2011-10-11 00:28:45 +000051 FnD = Actions.ActOnFriendFunctionDecl(getCurScope(), D,
Benjamin Kramer62b95d82012-08-23 21:35:17 +000052 TemplateParams);
Douglas Gregor728d00b2011-10-10 14:49:18 +000053 else {
Douglas Gregor0be31a22010-07-02 17:43:08 +000054 FnD = Actions.ActOnCXXMemberDeclarator(getCurScope(), AS, D,
Benjamin Kramer62b95d82012-08-23 21:35:17 +000055 TemplateParams, 0,
Richard Smith2b013182012-06-10 03:12:00 +000056 VS, ICIS_NoInit);
Douglas Gregor728d00b2011-10-10 14:49:18 +000057 if (FnD) {
Larisse Voufo39a1e502013-08-06 01:03:05 +000058 Actions.ProcessDeclAttributeList(getCurScope(), FnD, AccessAttrs, false,
59 true);
Richard Smith74aeef52013-04-26 16:15:35 +000060 bool TypeSpecContainsAuto = D.getDeclSpec().containsPlaceholderType();
Douglas Gregor50cefbf2011-10-17 17:09:53 +000061 if (Init.isUsable())
Larisse Voufo39a1e502013-08-06 01:03:05 +000062 Actions.AddInitializerToDecl(FnD, Init.get(), false,
Douglas Gregor728d00b2011-10-10 14:49:18 +000063 TypeSpecContainsAuto);
64 else
65 Actions.ActOnUninitializedDecl(FnD, TypeSpecContainsAuto);
66 }
Nico Weber24b2a822011-01-28 06:07:34 +000067 }
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +000068
Douglas Gregor433e0532012-04-16 18:27:27 +000069 HandleMemberFunctionDeclDelays(D, FnD);
Eli Friedman3af2a772009-07-22 21:45:50 +000070
John McCallc1465822011-02-14 07:13:47 +000071 D.complete(FnD);
72
Alexis Hunt5a7fa252011-05-12 06:15:49 +000073 if (Tok.is(tok::equal)) {
74 ConsumeToken();
75
Richard Smith1c704732011-11-10 09:08:44 +000076 if (!FnD) {
77 SkipUntil(tok::semi);
78 return 0;
79 }
80
Alexis Hunt5a7fa252011-05-12 06:15:49 +000081 bool Delete = false;
82 SourceLocation KWLoc;
83 if (Tok.is(tok::kw_delete)) {
Richard Smith2bf7fdb2013-01-02 11:42:31 +000084 Diag(Tok, getLangOpts().CPlusPlus11 ?
Richard Smith5d164bc2011-10-15 05:09:34 +000085 diag::warn_cxx98_compat_deleted_function :
Richard Smithe4345902011-12-29 21:57:33 +000086 diag::ext_deleted_function);
Alexis Hunt5a7fa252011-05-12 06:15:49 +000087
88 KWLoc = ConsumeToken();
89 Actions.SetDeclDeleted(FnD, KWLoc);
90 Delete = true;
91 } else if (Tok.is(tok::kw_default)) {
Richard Smith2bf7fdb2013-01-02 11:42:31 +000092 Diag(Tok, getLangOpts().CPlusPlus11 ?
Richard Smith5d164bc2011-10-15 05:09:34 +000093 diag::warn_cxx98_compat_defaulted_function :
Richard Smithe4345902011-12-29 21:57:33 +000094 diag::ext_defaulted_function);
Alexis Hunt5a7fa252011-05-12 06:15:49 +000095
96 KWLoc = ConsumeToken();
97 Actions.SetDeclDefaulted(FnD, KWLoc);
98 } else {
99 llvm_unreachable("function definition after = not 'delete' or 'default'");
100 }
101
102 if (Tok.is(tok::comma)) {
103 Diag(KWLoc, diag::err_default_delete_in_multiple_declaration)
104 << Delete;
105 SkipUntil(tok::semi);
106 } else {
107 ExpectAndConsume(tok::semi, diag::err_expected_semi_after,
108 Delete ? "delete" : "default", tok::semi);
109 }
110
111 return FnD;
112 }
113
Francois Pichet1c229c02011-04-22 22:18:13 +0000114 // In delayed template parsing mode, if we are within a class template
115 // or if we are about to parse function member template then consume
116 // the tokens and store them for parsing at the end of the translation unit.
David Blaikiebbafb8a2012-03-11 07:00:24 +0000117 if (getLangOpts().DelayedTemplateParsing &&
Douglas Gregor1edf5762012-06-28 21:43:01 +0000118 DefinitionKind == FDK_Definition &&
Francois Pichet1c229c02011-04-22 22:18:13 +0000119 ((Actions.CurContext->isDependentContext() ||
120 TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate) &&
Francois Pichet6dc4c162011-11-18 23:47:17 +0000121 !Actions.IsInsideALocalClassWithinATemplateFunction())) {
Francois Pichet1c229c02011-04-22 22:18:13 +0000122
Richard Smithe40f2ba2013-08-07 21:41:30 +0000123 CachedTokens Toks;
124 LexTemplateFunctionForLateParsing(Toks);
Francois Pichet1c229c02011-04-22 22:18:13 +0000125
Richard Smithe40f2ba2013-08-07 21:41:30 +0000126 if (FnD) {
John McCalle68672f2013-03-14 05:13:41 +0000127 FunctionDecl *FD = getFunctionDecl(FnD);
Chandler Carruthbc0f9ae2011-04-25 07:09:43 +0000128 Actions.CheckForFunctionRedefinition(FD);
Richard Smithe40f2ba2013-08-07 21:41:30 +0000129 Actions.MarkAsLateParsedTemplate(FD, FnD, Toks);
Francois Pichet1c229c02011-04-22 22:18:13 +0000130 }
131
132 return FnD;
133 }
134
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000135 // Consume the tokens and store them for later parsing.
136
Douglas Gregorefc46952010-10-12 16:25:54 +0000137 LexedMethod* LM = new LexedMethod(this, FnD);
138 getCurrentClass().LateParsedDeclarations.push_back(LM);
139 LM->TemplateScope = getCurScope()->isTemplateParamScope();
140 CachedTokens &Toks = LM->Toks;
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000141
Sebastian Redla7b98a72009-04-26 20:35:05 +0000142 tok::TokenKind kind = Tok.getKind();
Sebastian Redl0d164012011-09-30 08:32:17 +0000143 // Consume everything up to (and including) the left brace of the
144 // function body.
145 if (ConsumeAndStoreFunctionPrologue(Toks)) {
146 // We didn't find the left-brace we expected after the
Eli Friedman7cd4a9b2012-02-22 04:49:04 +0000147 // constructor initializer; we already printed an error, and it's likely
148 // impossible to recover, so don't try to parse this method later.
Richard Smithcde3fd82013-07-04 00:13:48 +0000149 // Skip over the rest of the decl and back to somewhere that looks
150 // reasonable.
151 SkipMalformedDecl();
Eli Friedman7cd4a9b2012-02-22 04:49:04 +0000152 delete getCurrentClass().LateParsedDeclarations.back();
153 getCurrentClass().LateParsedDeclarations.pop_back();
154 return FnD;
Douglas Gregore8381c02008-11-05 04:29:56 +0000155 } else {
Sebastian Redl0d164012011-09-30 08:32:17 +0000156 // Consume everything up to (and including) the matching right brace.
157 ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false);
Douglas Gregore8381c02008-11-05 04:29:56 +0000158 }
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000159
Sebastian Redla7b98a72009-04-26 20:35:05 +0000160 // If we're in a function-try-block, we need to store all the catch blocks.
161 if (kind == tok::kw_try) {
162 while (Tok.is(tok::kw_catch)) {
Argyrios Kyrtzidis8d7bdba2010-04-23 21:20:12 +0000163 ConsumeAndStoreUntil(tok::l_brace, Toks, /*StopAtSemi=*/false);
164 ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false);
Sebastian Redla7b98a72009-04-26 20:35:05 +0000165 }
166 }
167
Stephen Lin9354fc52013-06-23 07:37:13 +0000168 if (FnD) {
169 // If this is a friend function, mark that it's late-parsed so that
170 // it's still known to be a definition even before we attach the
171 // parsed body. Sema needs to treat friend function definitions
172 // differently during template instantiation, and it's possible for
173 // the containing class to be instantiated before all its member
174 // function definitions are parsed.
175 //
176 // If you remove this, you can remove the code that clears the flag
177 // after parsing the member.
178 if (D.getDeclSpec().isFriendSpecified()) {
179 getFunctionDecl(FnD)->setLateTemplateParsed(true);
180 }
181 } else {
Douglas Gregor6ca64102011-04-14 23:19:27 +0000182 // If semantic analysis could not build a function declaration,
183 // just throw away the late-parsed declaration.
184 delete getCurrentClass().LateParsedDeclarations.back();
185 getCurrentClass().LateParsedDeclarations.pop_back();
186 }
187
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000188 return FnD;
189}
190
Richard Smith938f40b2011-06-11 17:19:42 +0000191/// ParseCXXNonStaticMemberInitializer - We parsed and verified that the
192/// specified Declarator is a well formed C++ non-static data member
193/// declaration. Now lex its initializer and store its tokens for parsing
194/// after the class is complete.
195void Parser::ParseCXXNonStaticMemberInitializer(Decl *VarD) {
196 assert((Tok.is(tok::l_brace) || Tok.is(tok::equal)) &&
197 "Current token not a '{' or '='!");
198
199 LateParsedMemberInitializer *MI =
200 new LateParsedMemberInitializer(this, VarD);
201 getCurrentClass().LateParsedDeclarations.push_back(MI);
202 CachedTokens &Toks = MI->Toks;
203
204 tok::TokenKind kind = Tok.getKind();
205 if (kind == tok::equal) {
206 Toks.push_back(Tok);
Douglas Gregor0cf55e92012-03-08 01:00:17 +0000207 ConsumeToken();
Richard Smith938f40b2011-06-11 17:19:42 +0000208 }
209
210 if (kind == tok::l_brace) {
211 // Begin by storing the '{' token.
212 Toks.push_back(Tok);
213 ConsumeBrace();
214
215 // Consume everything up to (and including) the matching right brace.
216 ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/true);
217 } else {
218 // Consume everything up to (but excluding) the comma or semicolon.
219 ConsumeAndStoreUntil(tok::comma, Toks, /*StopAtSemi=*/true,
220 /*ConsumeFinalToken=*/false);
221 }
222
223 // Store an artificial EOF token to ensure that we don't run off the end of
224 // the initializer when we come to parse it.
225 Token Eof;
226 Eof.startToken();
227 Eof.setKind(tok::eof);
228 Eof.setLocation(Tok.getLocation());
229 Toks.push_back(Eof);
230}
231
Douglas Gregorefc46952010-10-12 16:25:54 +0000232Parser::LateParsedDeclaration::~LateParsedDeclaration() {}
233void Parser::LateParsedDeclaration::ParseLexedMethodDeclarations() {}
Richard Smith938f40b2011-06-11 17:19:42 +0000234void Parser::LateParsedDeclaration::ParseLexedMemberInitializers() {}
Douglas Gregorefc46952010-10-12 16:25:54 +0000235void Parser::LateParsedDeclaration::ParseLexedMethodDefs() {}
236
237Parser::LateParsedClass::LateParsedClass(Parser *P, ParsingClass *C)
238 : Self(P), Class(C) {}
239
240Parser::LateParsedClass::~LateParsedClass() {
241 Self->DeallocateParsedClasses(Class);
242}
243
244void Parser::LateParsedClass::ParseLexedMethodDeclarations() {
245 Self->ParseLexedMethodDeclarations(*Class);
246}
247
Richard Smith938f40b2011-06-11 17:19:42 +0000248void Parser::LateParsedClass::ParseLexedMemberInitializers() {
249 Self->ParseLexedMemberInitializers(*Class);
250}
251
Douglas Gregorefc46952010-10-12 16:25:54 +0000252void Parser::LateParsedClass::ParseLexedMethodDefs() {
253 Self->ParseLexedMethodDefs(*Class);
254}
255
256void Parser::LateParsedMethodDeclaration::ParseLexedMethodDeclarations() {
257 Self->ParseLexedMethodDeclaration(*this);
258}
259
260void Parser::LexedMethod::ParseLexedMethodDefs() {
261 Self->ParseLexedMethodDef(*this);
262}
263
Richard Smith938f40b2011-06-11 17:19:42 +0000264void Parser::LateParsedMemberInitializer::ParseLexedMemberInitializers() {
265 Self->ParseLexedMemberInitializer(*this);
266}
267
Douglas Gregor4d87df52008-12-16 21:30:33 +0000268/// ParseLexedMethodDeclarations - We finished parsing the member
269/// specification of a top (non-nested) C++ class. Now go over the
270/// stack of method declarations with some parts for which parsing was
271/// delayed (such as default arguments) and parse them.
Douglas Gregore44a2ad2009-05-27 23:11:45 +0000272void Parser::ParseLexedMethodDeclarations(ParsingClass &Class) {
273 bool HasTemplateScope = !Class.TopLevelClass && Class.TemplateScope;
Douglas Gregorefc46952010-10-12 16:25:54 +0000274 ParseScope ClassTemplateScope(this, Scope::TemplateParamScope, HasTemplateScope);
Richard Smithc8378952013-04-29 11:55:38 +0000275 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
276 if (HasTemplateScope) {
Douglas Gregor0be31a22010-07-02 17:43:08 +0000277 Actions.ActOnReenterTemplateScope(getCurScope(), Class.TagOrTemplate);
Richard Smithc8378952013-04-29 11:55:38 +0000278 ++CurTemplateDepthTracker;
279 }
Douglas Gregore44a2ad2009-05-27 23:11:45 +0000280
John McCall6df5fef2009-12-19 10:49:29 +0000281 // The current scope is still active if we're the top-level class.
282 // Otherwise we'll need to push and enter a new scope.
Douglas Gregore44a2ad2009-05-27 23:11:45 +0000283 bool HasClassScope = !Class.TopLevelClass;
Alexis Hunt1deb9722010-04-14 23:07:37 +0000284 ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope,
285 HasClassScope);
John McCall6df5fef2009-12-19 10:49:29 +0000286 if (HasClassScope)
Douglas Gregor0be31a22010-07-02 17:43:08 +0000287 Actions.ActOnStartDelayedMemberDeclarations(getCurScope(), Class.TagOrTemplate);
Douglas Gregore44a2ad2009-05-27 23:11:45 +0000288
Douglas Gregorefc46952010-10-12 16:25:54 +0000289 for (size_t i = 0; i < Class.LateParsedDeclarations.size(); ++i) {
290 Class.LateParsedDeclarations[i]->ParseLexedMethodDeclarations();
Douglas Gregor4d87df52008-12-16 21:30:33 +0000291 }
Douglas Gregore44a2ad2009-05-27 23:11:45 +0000292
John McCall6df5fef2009-12-19 10:49:29 +0000293 if (HasClassScope)
Douglas Gregor0be31a22010-07-02 17:43:08 +0000294 Actions.ActOnFinishDelayedMemberDeclarations(getCurScope(), Class.TagOrTemplate);
Douglas Gregor4d87df52008-12-16 21:30:33 +0000295}
296
Douglas Gregorefc46952010-10-12 16:25:54 +0000297void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) {
298 // If this is a member template, introduce the template parameter scope.
299 ParseScope TemplateScope(this, Scope::TemplateParamScope, LM.TemplateScope);
Richard Smithc8378952013-04-29 11:55:38 +0000300 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
301 if (LM.TemplateScope) {
Douglas Gregorefc46952010-10-12 16:25:54 +0000302 Actions.ActOnReenterTemplateScope(getCurScope(), LM.Method);
Richard Smithc8378952013-04-29 11:55:38 +0000303 ++CurTemplateDepthTracker;
304 }
Douglas Gregorefc46952010-10-12 16:25:54 +0000305 // Start the delayed C++ method declaration
306 Actions.ActOnStartDelayedCXXMethodDeclaration(getCurScope(), LM.Method);
307
308 // Introduce the parameters into scope and parse their default
309 // arguments.
Richard Smithe233fbf2013-01-28 22:42:45 +0000310 ParseScope PrototypeScope(this, Scope::FunctionPrototypeScope |
311 Scope::FunctionDeclarationScope | Scope::DeclScope);
Douglas Gregorefc46952010-10-12 16:25:54 +0000312 for (unsigned I = 0, N = LM.DefaultArgs.size(); I != N; ++I) {
313 // Introduce the parameter into scope.
Douglas Gregor7fcbd902012-02-21 00:37:24 +0000314 Actions.ActOnDelayedCXXMethodParameter(getCurScope(),
315 LM.DefaultArgs[I].Param);
Douglas Gregorefc46952010-10-12 16:25:54 +0000316
317 if (CachedTokens *Toks = LM.DefaultArgs[I].Toks) {
318 // Save the current token position.
319 SourceLocation origLoc = Tok.getLocation();
320
321 // Parse the default argument from its saved token stream.
322 Toks->push_back(Tok); // So that the current token doesn't get lost
323 PP.EnterTokenStream(&Toks->front(), Toks->size(), true, false);
324
325 // Consume the previously-pushed token.
326 ConsumeAnyToken();
327
328 // Consume the '='.
329 assert(Tok.is(tok::equal) && "Default argument not starting with '='");
330 SourceLocation EqualLoc = ConsumeToken();
331
332 // The argument isn't actually potentially evaluated unless it is
333 // used.
334 EnterExpressionEvaluationContext Eval(Actions,
Douglas Gregor7fcbd902012-02-21 00:37:24 +0000335 Sema::PotentiallyEvaluatedIfUsed,
336 LM.DefaultArgs[I].Param);
Douglas Gregorefc46952010-10-12 16:25:54 +0000337
Sebastian Redldb63af22012-03-14 15:54:00 +0000338 ExprResult DefArgResult;
Richard Smith2bf7fdb2013-01-02 11:42:31 +0000339 if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) {
Sebastian Redl6db0b1b2012-03-20 21:24:03 +0000340 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
Sebastian Redldb63af22012-03-14 15:54:00 +0000341 DefArgResult = ParseBraceInitializer();
Sebastian Redl6db0b1b2012-03-20 21:24:03 +0000342 } else
Sebastian Redldb63af22012-03-14 15:54:00 +0000343 DefArgResult = ParseAssignmentExpression();
Douglas Gregorefc46952010-10-12 16:25:54 +0000344 if (DefArgResult.isInvalid())
345 Actions.ActOnParamDefaultArgumentError(LM.DefaultArgs[I].Param);
346 else {
347 if (Tok.is(tok::cxx_defaultarg_end))
348 ConsumeToken();
349 else
350 Diag(Tok.getLocation(), diag::err_default_arg_unparsed);
351 Actions.ActOnParamDefaultArgument(LM.DefaultArgs[I].Param, EqualLoc,
352 DefArgResult.take());
353 }
354
355 assert(!PP.getSourceManager().isBeforeInTranslationUnit(origLoc,
356 Tok.getLocation()) &&
357 "ParseAssignmentExpression went over the default arg tokens!");
358 // There could be leftover tokens (e.g. because of an error).
359 // Skip through until we reach the original token position.
360 while (Tok.getLocation() != origLoc && Tok.isNot(tok::eof))
361 ConsumeAnyToken();
362
363 delete Toks;
364 LM.DefaultArgs[I].Toks = 0;
365 }
366 }
Douglas Gregor433e0532012-04-16 18:27:27 +0000367
Douglas Gregorefc46952010-10-12 16:25:54 +0000368 PrototypeScope.Exit();
369
370 // Finish the delayed C++ method declaration.
371 Actions.ActOnFinishDelayedCXXMethodDeclaration(getCurScope(), LM.Method);
372}
373
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000374/// ParseLexedMethodDefs - We finished parsing the member specification of a top
375/// (non-nested) C++ class. Now go over the stack of lexed methods that were
376/// collected during its parsing and parse them all.
Douglas Gregore44a2ad2009-05-27 23:11:45 +0000377void Parser::ParseLexedMethodDefs(ParsingClass &Class) {
378 bool HasTemplateScope = !Class.TopLevelClass && Class.TemplateScope;
Douglas Gregorefc46952010-10-12 16:25:54 +0000379 ParseScope ClassTemplateScope(this, Scope::TemplateParamScope, HasTemplateScope);
Richard Smithc8378952013-04-29 11:55:38 +0000380 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
381 if (HasTemplateScope) {
Douglas Gregor0be31a22010-07-02 17:43:08 +0000382 Actions.ActOnReenterTemplateScope(getCurScope(), Class.TagOrTemplate);
Richard Smithc8378952013-04-29 11:55:38 +0000383 ++CurTemplateDepthTracker;
384 }
Douglas Gregore44a2ad2009-05-27 23:11:45 +0000385 bool HasClassScope = !Class.TopLevelClass;
386 ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope,
387 HasClassScope);
388
Douglas Gregorefc46952010-10-12 16:25:54 +0000389 for (size_t i = 0; i < Class.LateParsedDeclarations.size(); ++i) {
390 Class.LateParsedDeclarations[i]->ParseLexedMethodDefs();
391 }
392}
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000393
Douglas Gregorefc46952010-10-12 16:25:54 +0000394void Parser::ParseLexedMethodDef(LexedMethod &LM) {
395 // If this is a member template, introduce the template parameter scope.
396 ParseScope TemplateScope(this, Scope::TemplateParamScope, LM.TemplateScope);
Richard Smithc8378952013-04-29 11:55:38 +0000397 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
398 if (LM.TemplateScope) {
Douglas Gregorefc46952010-10-12 16:25:54 +0000399 Actions.ActOnReenterTemplateScope(getCurScope(), LM.D);
Richard Smithc8378952013-04-29 11:55:38 +0000400 ++CurTemplateDepthTracker;
401 }
Douglas Gregorefc46952010-10-12 16:25:54 +0000402 // Save the current token position.
403 SourceLocation origLoc = Tok.getLocation();
Argyrios Kyrtzidis02041972010-03-31 00:38:09 +0000404
Douglas Gregorefc46952010-10-12 16:25:54 +0000405 assert(!LM.Toks.empty() && "Empty body!");
406 // Append the current token at the end of the new token stream so that it
407 // doesn't get lost.
408 LM.Toks.push_back(Tok);
409 PP.EnterTokenStream(LM.Toks.data(), LM.Toks.size(), true, false);
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000410
Douglas Gregorefc46952010-10-12 16:25:54 +0000411 // Consume the previously pushed token.
Argyrios Kyrtzidisc36633c2013-03-27 23:58:17 +0000412 ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
Douglas Gregorefc46952010-10-12 16:25:54 +0000413 assert((Tok.is(tok::l_brace) || Tok.is(tok::colon) || Tok.is(tok::kw_try))
414 && "Inline method not starting with '{', ':' or 'try'");
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000415
Douglas Gregorefc46952010-10-12 16:25:54 +0000416 // Parse the method body. Function body parsing code is similar enough
417 // to be re-used for method bodies as well.
418 ParseScope FnScope(this, Scope::FnScope|Scope::DeclScope);
419 Actions.ActOnStartOfFunctionDef(getCurScope(), LM.D);
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000420
Douglas Gregorefc46952010-10-12 16:25:54 +0000421 if (Tok.is(tok::kw_try)) {
Douglas Gregora0ff0c32011-03-16 17:05:57 +0000422 ParseFunctionTryBlock(LM.D, FnScope);
Douglas Gregorefc46952010-10-12 16:25:54 +0000423 assert(!PP.getSourceManager().isBeforeInTranslationUnit(origLoc,
424 Tok.getLocation()) &&
425 "ParseFunctionTryBlock went over the cached tokens!");
426 // There could be leftover tokens (e.g. because of an error).
427 // Skip through until we reach the original token position.
428 while (Tok.getLocation() != origLoc && Tok.isNot(tok::eof))
429 ConsumeAnyToken();
430 return;
431 }
432 if (Tok.is(tok::colon)) {
433 ParseConstructorInitializer(LM.D);
434
435 // Error recovery.
436 if (!Tok.is(tok::l_brace)) {
Douglas Gregora0ff0c32011-03-16 17:05:57 +0000437 FnScope.Exit();
Douglas Gregorefc46952010-10-12 16:25:54 +0000438 Actions.ActOnFinishFunctionBody(LM.D, 0);
Matt Beaumont-Gayd0457922011-09-23 22:39:23 +0000439 while (Tok.getLocation() != origLoc && Tok.isNot(tok::eof))
440 ConsumeAnyToken();
Douglas Gregorefc46952010-10-12 16:25:54 +0000441 return;
442 }
443 } else
444 Actions.ActOnDefaultCtorInitializers(LM.D);
445
Richard Smithc8378952013-04-29 11:55:38 +0000446 assert((Actions.getDiagnostics().hasErrorOccurred() ||
447 !isa<FunctionTemplateDecl>(LM.D) ||
448 cast<FunctionTemplateDecl>(LM.D)->getTemplateParameters()->getDepth()
449 < TemplateParameterDepth) &&
450 "TemplateParameterDepth should be greater than the depth of "
451 "current template being instantiated!");
452
Douglas Gregora0ff0c32011-03-16 17:05:57 +0000453 ParseFunctionStatementBody(LM.D, FnScope);
Douglas Gregorefc46952010-10-12 16:25:54 +0000454
John McCalle68672f2013-03-14 05:13:41 +0000455 // Clear the late-template-parsed bit if we set it before.
456 if (LM.D) getFunctionDecl(LM.D)->setLateTemplateParsed(false);
457
Douglas Gregorefc46952010-10-12 16:25:54 +0000458 if (Tok.getLocation() != origLoc) {
459 // Due to parsing error, we either went over the cached tokens or
460 // there are still cached tokens left. If it's the latter case skip the
461 // leftover tokens.
462 // Since this is an uncommon situation that should be avoided, use the
463 // expensive isBeforeInTranslationUnit call.
464 if (PP.getSourceManager().isBeforeInTranslationUnit(Tok.getLocation(),
465 origLoc))
Argyrios Kyrtzidise1224c82010-06-19 19:58:34 +0000466 while (Tok.getLocation() != origLoc && Tok.isNot(tok::eof))
Argyrios Kyrtzidise9b76af2010-06-17 10:52:22 +0000467 ConsumeAnyToken();
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000468 }
469}
470
Richard Smith938f40b2011-06-11 17:19:42 +0000471/// ParseLexedMemberInitializers - We finished parsing the member specification
472/// of a top (non-nested) C++ class. Now go over the stack of lexed data member
473/// initializers that were collected during its parsing and parse them all.
474void Parser::ParseLexedMemberInitializers(ParsingClass &Class) {
475 bool HasTemplateScope = !Class.TopLevelClass && Class.TemplateScope;
476 ParseScope ClassTemplateScope(this, Scope::TemplateParamScope,
477 HasTemplateScope);
Richard Smithc8378952013-04-29 11:55:38 +0000478 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
479 if (HasTemplateScope) {
Richard Smith938f40b2011-06-11 17:19:42 +0000480 Actions.ActOnReenterTemplateScope(getCurScope(), Class.TagOrTemplate);
Richard Smithc8378952013-04-29 11:55:38 +0000481 ++CurTemplateDepthTracker;
482 }
Douglas Gregor3024f072012-04-16 07:05:22 +0000483 // Set or update the scope flags.
Richard Smith938f40b2011-06-11 17:19:42 +0000484 bool AlreadyHasClassScope = Class.TopLevelClass;
Douglas Gregor3024f072012-04-16 07:05:22 +0000485 unsigned ScopeFlags = Scope::ClassScope|Scope::DeclScope;
Richard Smith938f40b2011-06-11 17:19:42 +0000486 ParseScope ClassScope(this, ScopeFlags, !AlreadyHasClassScope);
487 ParseScopeFlags ClassScopeFlags(this, ScopeFlags, AlreadyHasClassScope);
488
489 if (!AlreadyHasClassScope)
490 Actions.ActOnStartDelayedMemberDeclarations(getCurScope(),
491 Class.TagOrTemplate);
492
Benjamin Kramer1d373c62012-05-17 12:01:52 +0000493 if (!Class.LateParsedDeclarations.empty()) {
Douglas Gregor3024f072012-04-16 07:05:22 +0000494 // C++11 [expr.prim.general]p4:
495 // Otherwise, if a member-declarator declares a non-static data member
496 // (9.2) of a class X, the expression this is a prvalue of type "pointer
497 // to X" within the optional brace-or-equal-initializer. It shall not
498 // appear elsewhere in the member-declarator.
499 Sema::CXXThisScopeRAII ThisScope(Actions, Class.TagOrTemplate,
500 /*TypeQuals=*/(unsigned)0);
Richard Smith938f40b2011-06-11 17:19:42 +0000501
Douglas Gregor3024f072012-04-16 07:05:22 +0000502 for (size_t i = 0; i < Class.LateParsedDeclarations.size(); ++i) {
503 Class.LateParsedDeclarations[i]->ParseLexedMemberInitializers();
504 }
505 }
506
Richard Smith938f40b2011-06-11 17:19:42 +0000507 if (!AlreadyHasClassScope)
508 Actions.ActOnFinishDelayedMemberDeclarations(getCurScope(),
509 Class.TagOrTemplate);
510
511 Actions.ActOnFinishDelayedMemberInitializers(Class.TagOrTemplate);
512}
513
514void Parser::ParseLexedMemberInitializer(LateParsedMemberInitializer &MI) {
Richard Smith1a526fd2011-09-29 19:42:27 +0000515 if (!MI.Field || MI.Field->isInvalidDecl())
Richard Smith938f40b2011-06-11 17:19:42 +0000516 return;
517
518 // Append the current token at the end of the new token stream so that it
519 // doesn't get lost.
520 MI.Toks.push_back(Tok);
521 PP.EnterTokenStream(MI.Toks.data(), MI.Toks.size(), true, false);
522
523 // Consume the previously pushed token.
Argyrios Kyrtzidisc36633c2013-03-27 23:58:17 +0000524 ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
Richard Smith938f40b2011-06-11 17:19:42 +0000525
526 SourceLocation EqualLoc;
Richard Smith2b013182012-06-10 03:12:00 +0000527
Douglas Gregor926410d2012-02-21 02:22:07 +0000528 ExprResult Init = ParseCXXMemberInitializer(MI.Field, /*IsFunction=*/false,
529 EqualLoc);
Richard Smith938f40b2011-06-11 17:19:42 +0000530
531 Actions.ActOnCXXInClassMemberInitializer(MI.Field, EqualLoc, Init.release());
532
533 // The next token should be our artificial terminating EOF token.
534 if (Tok.isNot(tok::eof)) {
535 SourceLocation EndLoc = PP.getLocForEndOfToken(PrevTokLocation);
536 if (!EndLoc.isValid())
537 EndLoc = Tok.getLocation();
538 // No fixit; we can't recover as if there were a semicolon here.
539 Diag(EndLoc, diag::err_expected_semi_decl_list);
540
541 // Consume tokens until we hit the artificial EOF.
542 while (Tok.isNot(tok::eof))
543 ConsumeAnyToken();
544 }
545 ConsumeAnyToken();
546}
547
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000548/// ConsumeAndStoreUntil - Consume and store the token at the passed token
Douglas Gregor4d87df52008-12-16 21:30:33 +0000549/// container until the token 'T' is reached (which gets
Mike Stump11289f42009-09-09 15:08:12 +0000550/// consumed/stored too, if ConsumeFinalToken).
Argyrios Kyrtzidis8d7bdba2010-04-23 21:20:12 +0000551/// If StopAtSemi is true, then we will stop early at a ';' character.
Douglas Gregor4d87df52008-12-16 21:30:33 +0000552/// Returns true if token 'T1' or 'T2' was found.
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000553/// NOTE: This is a specialized version of Parser::SkipUntil.
Douglas Gregor4d87df52008-12-16 21:30:33 +0000554bool Parser::ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2,
555 CachedTokens &Toks,
Argyrios Kyrtzidis8d7bdba2010-04-23 21:20:12 +0000556 bool StopAtSemi, bool ConsumeFinalToken) {
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000557 // We always want this function to consume at least one token if the first
558 // token isn't T and if not at EOF.
559 bool isFirstTokenConsumed = true;
560 while (1) {
561 // If we found one of the tokens, stop and return true.
Douglas Gregor4d87df52008-12-16 21:30:33 +0000562 if (Tok.is(T1) || Tok.is(T2)) {
563 if (ConsumeFinalToken) {
564 Toks.push_back(Tok);
565 ConsumeAnyToken();
566 }
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000567 return true;
568 }
569
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000570 switch (Tok.getKind()) {
571 case tok::eof:
572 // Ran out of tokens.
573 return false;
574
575 case tok::l_paren:
576 // Recursively consume properly-nested parens.
577 Toks.push_back(Tok);
578 ConsumeParen();
Argyrios Kyrtzidis8d7bdba2010-04-23 21:20:12 +0000579 ConsumeAndStoreUntil(tok::r_paren, Toks, /*StopAtSemi=*/false);
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000580 break;
581 case tok::l_square:
582 // Recursively consume properly-nested square brackets.
583 Toks.push_back(Tok);
584 ConsumeBracket();
Argyrios Kyrtzidis8d7bdba2010-04-23 21:20:12 +0000585 ConsumeAndStoreUntil(tok::r_square, Toks, /*StopAtSemi=*/false);
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000586 break;
587 case tok::l_brace:
588 // Recursively consume properly-nested braces.
589 Toks.push_back(Tok);
590 ConsumeBrace();
Argyrios Kyrtzidis8d7bdba2010-04-23 21:20:12 +0000591 ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false);
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000592 break;
593
594 // Okay, we found a ']' or '}' or ')', which we think should be balanced.
595 // Since the user wasn't looking for this token (if they were, it would
596 // already be handled), this isn't balanced. If there is a LHS token at a
597 // higher level, we will assume that this matches the unbalanced token
598 // and return it. Otherwise, this is a spurious RHS token, which we skip.
599 case tok::r_paren:
600 if (ParenCount && !isFirstTokenConsumed)
601 return false; // Matches something.
602 Toks.push_back(Tok);
603 ConsumeParen();
604 break;
605 case tok::r_square:
606 if (BracketCount && !isFirstTokenConsumed)
607 return false; // Matches something.
608 Toks.push_back(Tok);
609 ConsumeBracket();
610 break;
611 case tok::r_brace:
612 if (BraceCount && !isFirstTokenConsumed)
613 return false; // Matches something.
614 Toks.push_back(Tok);
615 ConsumeBrace();
616 break;
617
Argyrios Kyrtzidis5cec2ae2011-09-04 03:32:15 +0000618 case tok::code_completion:
619 Toks.push_back(Tok);
620 ConsumeCodeCompletionToken();
621 break;
622
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000623 case tok::string_literal:
624 case tok::wide_string_literal:
Douglas Gregorfb65e592011-07-27 05:40:30 +0000625 case tok::utf8_string_literal:
626 case tok::utf16_string_literal:
627 case tok::utf32_string_literal:
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000628 Toks.push_back(Tok);
629 ConsumeStringToken();
630 break;
Argyrios Kyrtzidis8d7bdba2010-04-23 21:20:12 +0000631 case tok::semi:
632 if (StopAtSemi)
633 return false;
634 // FALL THROUGH.
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000635 default:
636 // consume this token.
637 Toks.push_back(Tok);
638 ConsumeToken();
639 break;
640 }
641 isFirstTokenConsumed = false;
642 }
643}
Sebastian Redla74948d2011-09-24 17:48:25 +0000644
645/// \brief Consume tokens and store them in the passed token container until
646/// we've passed the try keyword and constructor initializers and have consumed
Sebastian Redl0d164012011-09-30 08:32:17 +0000647/// the opening brace of the function body. The opening brace will be consumed
648/// if and only if there was no error.
Sebastian Redla74948d2011-09-24 17:48:25 +0000649///
Richard Smithcde3fd82013-07-04 00:13:48 +0000650/// \return True on error.
Sebastian Redl0d164012011-09-30 08:32:17 +0000651bool Parser::ConsumeAndStoreFunctionPrologue(CachedTokens &Toks) {
Sebastian Redla74948d2011-09-24 17:48:25 +0000652 if (Tok.is(tok::kw_try)) {
653 Toks.push_back(Tok);
654 ConsumeToken();
655 }
Richard Smithcde3fd82013-07-04 00:13:48 +0000656
657 if (Tok.isNot(tok::colon)) {
658 // Easy case, just a function body.
659
660 // Grab any remaining garbage to be diagnosed later. We stop when we reach a
661 // brace: an opening one is the function body, while a closing one probably
662 // means we've reached the end of the class.
663 ConsumeAndStoreUntil(tok::l_brace, tok::r_brace, Toks,
664 /*StopAtSemi=*/true,
665 /*ConsumeFinalToken=*/false);
666 if (Tok.isNot(tok::l_brace))
667 return Diag(Tok.getLocation(), diag::err_expected_lbrace);
668
Sebastian Redla74948d2011-09-24 17:48:25 +0000669 Toks.push_back(Tok);
Richard Smithcde3fd82013-07-04 00:13:48 +0000670 ConsumeBrace();
671 return false;
Eli Friedman7cd4a9b2012-02-22 04:49:04 +0000672 }
Sebastian Redl0d164012011-09-30 08:32:17 +0000673
674 Toks.push_back(Tok);
Richard Smithcde3fd82013-07-04 00:13:48 +0000675 ConsumeToken();
676
677 // We can't reliably skip over a mem-initializer-id, because it could be
678 // a template-id involving not-yet-declared names. Given:
679 //
680 // S ( ) : a < b < c > ( e )
681 //
682 // 'e' might be an initializer or part of a template argument, depending
683 // on whether 'b' is a template.
684
685 // Track whether we might be inside a template argument. We can give
686 // significantly better diagnostics if we know that we're not.
687 bool MightBeTemplateArgument = false;
688
689 while (true) {
690 // Skip over the mem-initializer-id, if possible.
691 if (Tok.is(tok::kw_decltype)) {
692 Toks.push_back(Tok);
693 SourceLocation OpenLoc = ConsumeToken();
694 if (Tok.isNot(tok::l_paren))
695 return Diag(Tok.getLocation(), diag::err_expected_lparen_after)
696 << "decltype";
697 Toks.push_back(Tok);
698 ConsumeParen();
699 if (!ConsumeAndStoreUntil(tok::r_paren, Toks, /*StopAtSemi=*/true)) {
700 Diag(Tok.getLocation(), diag::err_expected_rparen);
701 Diag(OpenLoc, diag::note_matching) << "(";
702 return true;
703 }
704 }
705 do {
706 // Walk over a component of a nested-name-specifier.
707 if (Tok.is(tok::coloncolon)) {
708 Toks.push_back(Tok);
709 ConsumeToken();
710
711 if (Tok.is(tok::kw_template)) {
712 Toks.push_back(Tok);
713 ConsumeToken();
714 }
715 }
716
717 if (Tok.is(tok::identifier) || Tok.is(tok::kw_template)) {
718 Toks.push_back(Tok);
719 ConsumeToken();
720 } else if (Tok.is(tok::code_completion)) {
721 Toks.push_back(Tok);
722 ConsumeCodeCompletionToken();
723 // Consume the rest of the initializers permissively.
724 // FIXME: We should be able to perform code-completion here even if
725 // there isn't a subsequent '{' token.
726 MightBeTemplateArgument = true;
727 break;
728 } else {
729 break;
730 }
731 } while (Tok.is(tok::coloncolon));
732
733 if (Tok.is(tok::less))
734 MightBeTemplateArgument = true;
735
736 if (MightBeTemplateArgument) {
737 // We may be inside a template argument list. Grab up to the start of the
738 // next parenthesized initializer or braced-init-list. This *might* be the
739 // initializer, or it might be a subexpression in the template argument
740 // list.
741 // FIXME: Count angle brackets, and clear MightBeTemplateArgument
742 // if all angles are closed.
743 if (!ConsumeAndStoreUntil(tok::l_paren, tok::l_brace, Toks,
744 /*StopAtSemi=*/true,
745 /*ConsumeFinalToken=*/false)) {
746 // We're not just missing the initializer, we're also missing the
747 // function body!
748 return Diag(Tok.getLocation(), diag::err_expected_lbrace);
749 }
750 } else if (Tok.isNot(tok::l_paren) && Tok.isNot(tok::l_brace)) {
751 // We found something weird in a mem-initializer-id.
752 return Diag(Tok.getLocation(), getLangOpts().CPlusPlus11
753 ? diag::err_expected_lparen_or_lbrace
754 : diag::err_expected_lparen);
755 }
756
757 tok::TokenKind kind = Tok.getKind();
758 Toks.push_back(Tok);
759 bool IsLParen = (kind == tok::l_paren);
760 SourceLocation OpenLoc = Tok.getLocation();
761
762 if (IsLParen) {
763 ConsumeParen();
764 } else {
765 assert(kind == tok::l_brace && "Must be left paren or brace here.");
766 ConsumeBrace();
767 // In C++03, this has to be the start of the function body, which
768 // means the initializer is malformed; we'll diagnose it later.
769 if (!getLangOpts().CPlusPlus11)
770 return false;
771 }
772
773 // Grab the initializer (or the subexpression of the template argument).
774 // FIXME: If we support lambdas here, we'll need to set StopAtSemi to false
775 // if we might be inside the braces of a lambda-expression.
776 if (!ConsumeAndStoreUntil(IsLParen ? tok::r_paren : tok::r_brace,
777 Toks, /*StopAtSemi=*/true)) {
778 Diag(Tok, IsLParen ? diag::err_expected_rparen :
779 diag::err_expected_rbrace);
780 Diag(OpenLoc, diag::note_matching) << (IsLParen ? "(" : "{");
781 return true;
782 }
783
784 // Grab pack ellipsis, if present.
785 if (Tok.is(tok::ellipsis)) {
786 Toks.push_back(Tok);
787 ConsumeToken();
788 }
789
790 // If we know we just consumed a mem-initializer, we must have ',' or '{'
791 // next.
792 if (Tok.is(tok::comma)) {
793 Toks.push_back(Tok);
794 ConsumeToken();
795 } else if (Tok.is(tok::l_brace)) {
796 // This is the function body if the ')' or '}' is immediately followed by
797 // a '{'. That cannot happen within a template argument, apart from the
798 // case where a template argument contains a compound literal:
799 //
800 // S ( ) : a < b < c > ( d ) { }
801 // // End of declaration, or still inside the template argument?
802 //
803 // ... and the case where the template argument contains a lambda:
804 //
805 // S ( ) : a < 0 && b < c > ( d ) + [ ] ( ) { return 0; }
806 // ( ) > ( ) { }
807 //
808 // FIXME: Disambiguate these cases. Note that the latter case is probably
809 // going to be made ill-formed by core issue 1607.
810 Toks.push_back(Tok);
811 ConsumeBrace();
812 return false;
813 } else if (!MightBeTemplateArgument) {
814 return Diag(Tok.getLocation(), diag::err_expected_lbrace_or_comma);
815 }
816 }
Sebastian Redla74948d2011-09-24 17:48:25 +0000817}