1 //===--- ParseExprCXX.cpp - C++ Expression Parsing ------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the Expression parsing implementation for C++.
12 //===----------------------------------------------------------------------===//
14 #include "clang/Parse/ParseDiagnostic.h"
15 #include "clang/Parse/Parser.h"
16 #include "RAIIObjectsForParser.h"
17 #include "clang/Basic/PrettyStackTrace.h"
18 #include "clang/Lex/LiteralSupport.h"
19 #include "clang/Sema/DeclSpec.h"
20 #include "clang/Sema/Scope.h"
21 #include "clang/Sema/ParsedTemplate.h"
22 #include "llvm/Support/ErrorHandling.h"
24 using namespace clang;
26 static int SelectDigraphErrorMessage(tok::TokenKind Kind) {
28 case tok::kw_template: return 0;
29 case tok::kw_const_cast: return 1;
30 case tok::kw_dynamic_cast: return 2;
31 case tok::kw_reinterpret_cast: return 3;
32 case tok::kw_static_cast: return 4;
34 llvm_unreachable("Unknown type for digraph error message.");
38 // Are the two tokens adjacent in the same source file?
39 static bool AreTokensAdjacent(Preprocessor &PP, Token &First, Token &Second) {
40 SourceManager &SM = PP.getSourceManager();
41 SourceLocation FirstLoc = SM.getSpellingLoc(First.getLocation());
42 SourceLocation FirstEnd = FirstLoc.getLocWithOffset(First.getLength());
43 return FirstEnd == SM.getSpellingLoc(Second.getLocation());
46 // Suggest fixit for "<::" after a cast.
47 static void FixDigraph(Parser &P, Preprocessor &PP, Token &DigraphToken,
48 Token &ColonToken, tok::TokenKind Kind, bool AtDigraph) {
49 // Pull '<:' and ':' off token stream.
55 Range.setBegin(DigraphToken.getLocation());
56 Range.setEnd(ColonToken.getLocation());
57 P.Diag(DigraphToken.getLocation(), diag::err_missing_whitespace_digraph)
58 << SelectDigraphErrorMessage(Kind)
59 << FixItHint::CreateReplacement(Range, "< ::");
61 // Update token information to reflect their change in token type.
62 ColonToken.setKind(tok::coloncolon);
63 ColonToken.setLocation(ColonToken.getLocation().getLocWithOffset(-1));
64 ColonToken.setLength(2);
65 DigraphToken.setKind(tok::less);
66 DigraphToken.setLength(1);
68 // Push new tokens back to token stream.
69 PP.EnterToken(ColonToken);
71 PP.EnterToken(DigraphToken);
74 // Check for '<::' which should be '< ::' instead of '[:' when following
76 void Parser::CheckForTemplateAndDigraph(Token &Next, ParsedType ObjectType,
78 IdentifierInfo &II, CXXScopeSpec &SS) {
79 if (!Next.is(tok::l_square) || Next.getLength() != 2)
82 Token SecondToken = GetLookAheadToken(2);
83 if (!SecondToken.is(tok::colon) || !AreTokensAdjacent(PP, Next, SecondToken))
87 UnqualifiedId TemplateName;
88 TemplateName.setIdentifier(&II, Tok.getLocation());
89 bool MemberOfUnknownSpecialization;
90 if (!Actions.isTemplateName(getCurScope(), SS, /*hasTemplateKeyword=*/false,
91 TemplateName, ObjectType, EnteringContext,
92 Template, MemberOfUnknownSpecialization))
95 FixDigraph(*this, PP, Next, SecondToken, tok::kw_template,
99 /// \brief Parse global scope or nested-name-specifier if present.
101 /// Parses a C++ global scope specifier ('::') or nested-name-specifier (which
102 /// may be preceded by '::'). Note that this routine will not parse ::new or
103 /// ::delete; it will just leave them in the token stream.
105 /// '::'[opt] nested-name-specifier
108 /// nested-name-specifier:
110 /// namespace-name '::'
111 /// nested-name-specifier identifier '::'
112 /// nested-name-specifier 'template'[opt] simple-template-id '::'
115 /// \param SS the scope specifier that will be set to the parsed
116 /// nested-name-specifier (or empty)
118 /// \param ObjectType if this nested-name-specifier is being parsed following
119 /// the "." or "->" of a member access expression, this parameter provides the
120 /// type of the object whose members are being accessed.
122 /// \param EnteringContext whether we will be entering into the context of
123 /// the nested-name-specifier after parsing it.
125 /// \param MayBePseudoDestructor When non-NULL, points to a flag that
126 /// indicates whether this nested-name-specifier may be part of a
127 /// pseudo-destructor name. In this case, the flag will be set false
128 /// if we don't actually end up parsing a destructor name. Moreorover,
129 /// if we do end up determining that we are parsing a destructor name,
130 /// the last component of the nested-name-specifier is not parsed as
131 /// part of the scope specifier.
133 /// member access expression, e.g., the \p T:: in \p p->T::m.
135 /// \returns true if there was an error parsing a scope specifier
136 bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
137 ParsedType ObjectType,
138 bool EnteringContext,
139 bool *MayBePseudoDestructor,
141 assert(getLangOpts().CPlusPlus &&
142 "Call sites of this function should be guarded by checking for C++");
144 if (Tok.is(tok::annot_cxxscope)) {
145 Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(),
146 Tok.getAnnotationRange(),
152 bool HasScopeSpecifier = false;
154 if (Tok.is(tok::coloncolon)) {
155 // ::new and ::delete aren't nested-name-specifiers.
156 tok::TokenKind NextKind = NextToken().getKind();
157 if (NextKind == tok::kw_new || NextKind == tok::kw_delete)
160 // '::' - Global scope qualifier.
161 if (Actions.ActOnCXXGlobalScopeSpecifier(getCurScope(), ConsumeToken(), SS))
164 HasScopeSpecifier = true;
167 bool CheckForDestructor = false;
168 if (MayBePseudoDestructor && *MayBePseudoDestructor) {
169 CheckForDestructor = true;
170 *MayBePseudoDestructor = false;
173 if (Tok.is(tok::kw_decltype) || Tok.is(tok::annot_decltype)) {
174 DeclSpec DS(AttrFactory);
175 SourceLocation DeclLoc = Tok.getLocation();
176 SourceLocation EndLoc = ParseDecltypeSpecifier(DS);
177 if (Tok.isNot(tok::coloncolon)) {
178 AnnotateExistingDecltypeSpecifier(DS, DeclLoc, EndLoc);
182 SourceLocation CCLoc = ConsumeToken();
183 if (Actions.ActOnCXXNestedNameSpecifierDecltype(SS, DS, CCLoc))
184 SS.SetInvalid(SourceRange(DeclLoc, CCLoc));
186 HasScopeSpecifier = true;
190 if (HasScopeSpecifier) {
191 // C++ [basic.lookup.classref]p5:
192 // If the qualified-id has the form
194 // ::class-name-or-namespace-name::...
196 // the class-name-or-namespace-name is looked up in global scope as a
197 // class-name or namespace-name.
199 // To implement this, we clear out the object type as soon as we've
200 // seen a leading '::' or part of a nested-name-specifier.
201 ObjectType = ParsedType();
203 if (Tok.is(tok::code_completion)) {
204 // Code completion for a nested-name-specifier, where the code
205 // code completion token follows the '::'.
206 Actions.CodeCompleteQualifiedId(getCurScope(), SS, EnteringContext);
207 // Include code completion token into the range of the scope otherwise
208 // when we try to annotate the scope tokens the dangling code completion
209 // token will cause assertion in
210 // Preprocessor::AnnotatePreviousCachedTokens.
211 SS.setEndLoc(Tok.getLocation());
217 // nested-name-specifier:
218 // nested-name-specifier 'template'[opt] simple-template-id '::'
220 // Parse the optional 'template' keyword, then make sure we have
221 // 'identifier <' after it.
222 if (Tok.is(tok::kw_template)) {
223 // If we don't have a scope specifier or an object type, this isn't a
224 // nested-name-specifier, since they aren't allowed to start with
226 if (!HasScopeSpecifier && !ObjectType)
229 TentativeParsingAction TPA(*this);
230 SourceLocation TemplateKWLoc = ConsumeToken();
232 UnqualifiedId TemplateName;
233 if (Tok.is(tok::identifier)) {
234 // Consume the identifier.
235 TemplateName.setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
237 } else if (Tok.is(tok::kw_operator)) {
238 if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType,
244 if (TemplateName.getKind() != UnqualifiedId::IK_OperatorFunctionId &&
245 TemplateName.getKind() != UnqualifiedId::IK_LiteralOperatorId) {
246 Diag(TemplateName.getSourceRange().getBegin(),
247 diag::err_id_after_template_in_nested_name_spec)
248 << TemplateName.getSourceRange();
257 // If the next token is not '<', we have a qualified-id that refers
258 // to a template name, such as T::template apply, but is not a
260 if (Tok.isNot(tok::less)) {
265 // Commit to parsing the template-id.
268 if (TemplateNameKind TNK
269 = Actions.ActOnDependentTemplateName(getCurScope(),
270 SS, TemplateKWLoc, TemplateName,
271 ObjectType, EnteringContext,
273 if (AnnotateTemplateIdToken(Template, TNK, SS, TemplateKWLoc,
274 TemplateName, false))
282 if (Tok.is(tok::annot_template_id) && NextToken().is(tok::coloncolon)) {
285 // simple-template-id '::'
287 // So we need to check whether the simple-template-id is of the
288 // right kind (it should name a type or be dependent), and then
289 // convert it into a type within the nested-name-specifier.
290 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
291 if (CheckForDestructor && GetLookAheadToken(2).is(tok::tilde)) {
292 *MayBePseudoDestructor = true;
296 // Consume the template-id token.
299 assert(Tok.is(tok::coloncolon) && "NextToken() not working properly!");
300 SourceLocation CCLoc = ConsumeToken();
302 HasScopeSpecifier = true;
304 ASTTemplateArgsPtr TemplateArgsPtr(Actions,
305 TemplateId->getTemplateArgs(),
306 TemplateId->NumArgs);
308 if (Actions.ActOnCXXNestedNameSpecifier(getCurScope(),
310 TemplateId->TemplateKWLoc,
311 TemplateId->Template,
312 TemplateId->TemplateNameLoc,
313 TemplateId->LAngleLoc,
315 TemplateId->RAngleLoc,
318 SourceLocation StartLoc
319 = SS.getBeginLoc().isValid()? SS.getBeginLoc()
320 : TemplateId->TemplateNameLoc;
321 SS.SetInvalid(SourceRange(StartLoc, CCLoc));
328 // The rest of the nested-name-specifier possibilities start with
330 if (Tok.isNot(tok::identifier))
333 IdentifierInfo &II = *Tok.getIdentifierInfo();
335 // nested-name-specifier:
337 // namespace-name '::'
338 // nested-name-specifier identifier '::'
339 Token Next = NextToken();
341 // If we get foo:bar, this is almost certainly a typo for foo::bar. Recover
342 // and emit a fixit hint for it.
343 if (Next.is(tok::colon) && !ColonIsSacred) {
344 if (Actions.IsInvalidUnlessNestedName(getCurScope(), SS, II,
346 Next.getLocation(), ObjectType,
348 // If the token after the colon isn't an identifier, it's still an
349 // error, but they probably meant something else strange so don't
350 // recover like this.
351 PP.LookAhead(1).is(tok::identifier)) {
352 Diag(Next, diag::err_unexected_colon_in_nested_name_spec)
353 << FixItHint::CreateReplacement(Next.getLocation(), "::");
355 // Recover as if the user wrote '::'.
356 Next.setKind(tok::coloncolon);
360 if (Next.is(tok::coloncolon)) {
361 if (CheckForDestructor && GetLookAheadToken(2).is(tok::tilde) &&
362 !Actions.isNonTypeNestedNameSpecifier(getCurScope(), SS, Tok.getLocation(),
364 *MayBePseudoDestructor = true;
368 // We have an identifier followed by a '::'. Lookup this name
369 // as the name in a nested-name-specifier.
370 SourceLocation IdLoc = ConsumeToken();
371 assert((Tok.is(tok::coloncolon) || Tok.is(tok::colon)) &&
372 "NextToken() not working properly!");
373 SourceLocation CCLoc = ConsumeToken();
375 HasScopeSpecifier = true;
376 if (Actions.ActOnCXXNestedNameSpecifier(getCurScope(), II, IdLoc, CCLoc,
377 ObjectType, EnteringContext, SS))
378 SS.SetInvalid(SourceRange(IdLoc, CCLoc));
383 CheckForTemplateAndDigraph(Next, ObjectType, EnteringContext, II, SS);
385 // nested-name-specifier:
387 if (Next.is(tok::less)) {
389 UnqualifiedId TemplateName;
390 TemplateName.setIdentifier(&II, Tok.getLocation());
391 bool MemberOfUnknownSpecialization;
392 if (TemplateNameKind TNK = Actions.isTemplateName(getCurScope(), SS,
393 /*hasTemplateKeyword=*/false,
398 MemberOfUnknownSpecialization)) {
399 // We have found a template name, so annotate this token
400 // with a template-id annotation. We do not permit the
401 // template-id to be translated into a type annotation,
402 // because some clients (e.g., the parsing of class template
403 // specializations) still want to see the original template-id
406 if (AnnotateTemplateIdToken(Template, TNK, SS, SourceLocation(),
407 TemplateName, false))
412 if (MemberOfUnknownSpecialization && (ObjectType || SS.isSet()) &&
413 (IsTypename || IsTemplateArgumentList(1))) {
414 // We have something like t::getAs<T>, where getAs is a
415 // member of an unknown specialization. However, this will only
416 // parse correctly as a template, so suggest the keyword 'template'
417 // before 'getAs' and treat this as a dependent template name.
418 unsigned DiagID = diag::err_missing_dependent_template_keyword;
419 if (getLangOpts().MicrosoftExt)
420 DiagID = diag::warn_missing_dependent_template_keyword;
422 Diag(Tok.getLocation(), DiagID)
424 << FixItHint::CreateInsertion(Tok.getLocation(), "template ");
426 if (TemplateNameKind TNK
427 = Actions.ActOnDependentTemplateName(getCurScope(),
428 SS, SourceLocation(),
429 TemplateName, ObjectType,
430 EnteringContext, Template)) {
431 // Consume the identifier.
433 if (AnnotateTemplateIdToken(Template, TNK, SS, SourceLocation(),
434 TemplateName, false))
444 // We don't have any tokens that form the beginning of a
445 // nested-name-specifier, so we're done.
449 // Even if we didn't see any pieces of a nested-name-specifier, we
450 // still check whether there is a tilde in this position, which
451 // indicates a potential pseudo-destructor.
452 if (CheckForDestructor && Tok.is(tok::tilde))
453 *MayBePseudoDestructor = true;
458 /// ParseCXXIdExpression - Handle id-expression.
465 /// '::'[opt] nested-name-specifier 'template'[opt] unqualified-id
467 /// '::' operator-function-id
470 /// NOTE: The standard specifies that, for qualified-id, the parser does not
473 /// '::' conversion-function-id
474 /// '::' '~' class-name
476 /// This may cause a slight inconsistency on diagnostics:
481 /// :: A :: ~ C(); // Some Sema error about using destructor with a
483 /// :: ~ C(); // Some Parser error like 'unexpected ~'.
486 /// We simplify the parser a bit and make it work like:
489 /// '::'[opt] nested-name-specifier 'template'[opt] unqualified-id
490 /// '::' unqualified-id
492 /// That way Sema can handle and report similar errors for namespaces and the
495 /// The isAddressOfOperand parameter indicates that this id-expression is a
496 /// direct operand of the address-of operator. This is, besides member contexts,
497 /// the only place where a qualified-id naming a non-static class member may
500 ExprResult Parser::ParseCXXIdExpression(bool isAddressOfOperand) {
502 // '::'[opt] nested-name-specifier 'template'[opt] unqualified-id
503 // '::' unqualified-id
506 ParseOptionalCXXScopeSpecifier(SS, ParsedType(), /*EnteringContext=*/false);
508 SourceLocation TemplateKWLoc;
510 if (ParseUnqualifiedId(SS,
511 /*EnteringContext=*/false,
512 /*AllowDestructorName=*/false,
513 /*AllowConstructorName=*/false,
514 /*ObjectType=*/ ParsedType(),
519 // This is only the direct operand of an & operator if it is not
520 // followed by a postfix-expression suffix.
521 if (isAddressOfOperand && isPostfixExpressionSuffixStart())
522 isAddressOfOperand = false;
524 return Actions.ActOnIdExpression(getCurScope(), SS, TemplateKWLoc, Name,
525 Tok.is(tok::l_paren), isAddressOfOperand);
528 /// ParseLambdaExpression - Parse a C++0x lambda expression.
530 /// lambda-expression:
531 /// lambda-introducer lambda-declarator[opt] compound-statement
533 /// lambda-introducer:
534 /// '[' lambda-capture[opt] ']'
539 /// capture-default ',' capture-list
547 /// capture-list ',' capture
554 /// lambda-declarator:
555 /// '(' parameter-declaration-clause ')' attribute-specifier[opt]
556 /// 'mutable'[opt] exception-specification[opt]
557 /// trailing-return-type[opt]
559 ExprResult Parser::ParseLambdaExpression() {
560 // Parse lambda-introducer.
561 LambdaIntroducer Intro;
563 llvm::Optional<unsigned> DiagID(ParseLambdaIntroducer(Intro));
565 Diag(Tok, DiagID.getValue());
566 SkipUntil(tok::r_square);
567 SkipUntil(tok::l_brace);
568 SkipUntil(tok::r_brace);
572 return ParseLambdaExpressionAfterIntroducer(Intro);
575 /// TryParseLambdaExpression - Use lookahead and potentially tentative
576 /// parsing to determine if we are looking at a C++0x lambda expression, and parse
579 /// If we are not looking at a lambda expression, returns ExprError().
580 ExprResult Parser::TryParseLambdaExpression() {
581 assert(getLangOpts().CPlusPlus0x
582 && Tok.is(tok::l_square)
583 && "Not at the start of a possible lambda expression.");
585 const Token Next = NextToken(), After = GetLookAheadToken(2);
587 // If lookahead indicates this is a lambda...
588 if (Next.is(tok::r_square) || // []
589 Next.is(tok::equal) || // [=
590 (Next.is(tok::amp) && // [&] or [&,
591 (After.is(tok::r_square) ||
592 After.is(tok::comma))) ||
593 (Next.is(tok::identifier) && // [identifier]
594 After.is(tok::r_square))) {
595 return ParseLambdaExpression();
598 // If lookahead indicates an ObjC message send...
599 // [identifier identifier
600 if (Next.is(tok::identifier) && After.is(tok::identifier)) {
604 // Here, we're stuck: lambda introducers and Objective-C message sends are
605 // unambiguous, but it requires arbitrary lookhead. [a,b,c,d,e,f,g] is a
606 // lambda, and [a,b,c,d,e,f,g h] is a Objective-C message send. Instead of
607 // writing two routines to parse a lambda introducer, just try to parse
608 // a lambda introducer first, and fall back if that fails.
609 // (TryParseLambdaIntroducer never produces any diagnostic output.)
610 LambdaIntroducer Intro;
611 if (TryParseLambdaIntroducer(Intro))
613 return ParseLambdaExpressionAfterIntroducer(Intro);
616 /// ParseLambdaExpression - Parse a lambda introducer.
618 /// Returns a DiagnosticID if it hit something unexpected.
619 llvm::Optional<unsigned> Parser::ParseLambdaIntroducer(LambdaIntroducer &Intro){
620 typedef llvm::Optional<unsigned> DiagResult;
622 assert(Tok.is(tok::l_square) && "Lambda expressions begin with '['.");
623 BalancedDelimiterTracker T(*this, tok::l_square);
626 Intro.Range.setBegin(T.getOpenLocation());
630 // Parse capture-default.
631 if (Tok.is(tok::amp) &&
632 (NextToken().is(tok::comma) || NextToken().is(tok::r_square))) {
633 Intro.Default = LCD_ByRef;
634 Intro.DefaultLoc = ConsumeToken();
636 } else if (Tok.is(tok::equal)) {
637 Intro.Default = LCD_ByCopy;
638 Intro.DefaultLoc = ConsumeToken();
642 while (Tok.isNot(tok::r_square)) {
644 if (Tok.isNot(tok::comma)) {
645 if (Tok.is(tok::code_completion)) {
646 Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro,
647 /*AfterAmpersand=*/false);
648 ConsumeCodeCompletionToken();
652 return DiagResult(diag::err_expected_comma_or_rsquare);
657 if (Tok.is(tok::code_completion)) {
658 // If we're in Objective-C++ and we have a bare '[', then this is more
659 // likely to be a message receiver.
660 if (getLangOpts().ObjC1 && first)
661 Actions.CodeCompleteObjCMessageReceiver(getCurScope());
663 Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro,
664 /*AfterAmpersand=*/false);
665 ConsumeCodeCompletionToken();
672 LambdaCaptureKind Kind = LCK_ByCopy;
674 IdentifierInfo* Id = 0;
675 SourceLocation EllipsisLoc;
677 if (Tok.is(tok::kw_this)) {
679 Loc = ConsumeToken();
681 if (Tok.is(tok::amp)) {
685 if (Tok.is(tok::code_completion)) {
686 Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro,
687 /*AfterAmpersand=*/true);
688 ConsumeCodeCompletionToken();
693 if (Tok.is(tok::identifier)) {
694 Id = Tok.getIdentifierInfo();
695 Loc = ConsumeToken();
697 if (Tok.is(tok::ellipsis))
698 EllipsisLoc = ConsumeToken();
699 } else if (Tok.is(tok::kw_this)) {
700 // FIXME: If we want to suggest a fixit here, will need to return more
701 // than just DiagnosticID. Perhaps full DiagnosticBuilder that can be
702 // Clear()ed to prevent emission in case of tentative parsing?
703 return DiagResult(diag::err_this_captured_by_reference);
705 return DiagResult(diag::err_expected_capture);
709 Intro.addCapture(Kind, Loc, Id, EllipsisLoc);
713 Intro.Range.setEnd(T.getCloseLocation());
718 /// TryParseLambdaIntroducer - Tentatively parse a lambda introducer.
720 /// Returns true if it hit something unexpected.
721 bool Parser::TryParseLambdaIntroducer(LambdaIntroducer &Intro) {
722 TentativeParsingAction PA(*this);
724 llvm::Optional<unsigned> DiagID(ParseLambdaIntroducer(Intro));
735 /// ParseLambdaExpressionAfterIntroducer - Parse the rest of a lambda
737 ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
738 LambdaIntroducer &Intro) {
739 SourceLocation LambdaBeginLoc = Intro.Range.getBegin();
740 Diag(LambdaBeginLoc, diag::warn_cxx98_compat_lambda);
742 PrettyStackTraceLoc CrashInfo(PP.getSourceManager(), LambdaBeginLoc,
743 "lambda expression parsing");
745 // Parse lambda-declarator[opt].
746 DeclSpec DS(AttrFactory);
747 Declarator D(DS, Declarator::LambdaExprContext);
749 if (Tok.is(tok::l_paren)) {
750 ParseScope PrototypeScope(this,
751 Scope::FunctionPrototypeScope |
754 SourceLocation DeclLoc, DeclEndLoc;
755 BalancedDelimiterTracker T(*this, tok::l_paren);
757 DeclLoc = T.getOpenLocation();
759 // Parse parameter-declaration-clause.
760 ParsedAttributes Attr(AttrFactory);
761 llvm::SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo;
762 SourceLocation EllipsisLoc;
764 if (Tok.isNot(tok::r_paren))
765 ParseParameterDeclarationClause(D, Attr, ParamInfo, EllipsisLoc);
768 DeclEndLoc = T.getCloseLocation();
770 // Parse 'mutable'[opt].
771 SourceLocation MutableLoc;
772 if (Tok.is(tok::kw_mutable)) {
773 MutableLoc = ConsumeToken();
774 DeclEndLoc = MutableLoc;
777 // Parse exception-specification[opt].
778 ExceptionSpecificationType ESpecType = EST_None;
779 SourceRange ESpecRange;
780 llvm::SmallVector<ParsedType, 2> DynamicExceptions;
781 llvm::SmallVector<SourceRange, 2> DynamicExceptionRanges;
782 ExprResult NoexceptExpr;
783 ESpecType = tryParseExceptionSpecification(ESpecRange,
785 DynamicExceptionRanges,
788 if (ESpecType != EST_None)
789 DeclEndLoc = ESpecRange.getEnd();
791 // Parse attribute-specifier[opt].
792 MaybeParseCXX0XAttributes(Attr, &DeclEndLoc);
794 // Parse trailing-return-type[opt].
795 ParsedType TrailingReturnType;
796 if (Tok.is(tok::arrow)) {
798 TrailingReturnType = ParseTrailingReturnType(Range).get();
799 if (Range.getEnd().isValid())
800 DeclEndLoc = Range.getEnd();
803 PrototypeScope.Exit();
805 D.AddTypeInfo(DeclaratorChunk::getFunction(/*hasProto=*/true,
806 /*isVariadic=*/EllipsisLoc.isValid(),
808 ParamInfo.data(), ParamInfo.size(),
809 DS.getTypeQualifiers(),
810 /*RefQualifierIsLValueRef=*/true,
811 /*RefQualifierLoc=*/SourceLocation(),
812 /*ConstQualifierLoc=*/SourceLocation(),
813 /*VolatileQualifierLoc=*/SourceLocation(),
815 ESpecType, ESpecRange.getBegin(),
816 DynamicExceptions.data(),
817 DynamicExceptionRanges.data(),
818 DynamicExceptions.size(),
819 NoexceptExpr.isUsable() ?
820 NoexceptExpr.get() : 0,
821 DeclLoc, DeclEndLoc, D,
824 } else if (Tok.is(tok::kw_mutable) || Tok.is(tok::arrow)) {
825 // It's common to forget that one needs '()' before 'mutable' or the
826 // result type. Deal with this.
827 Diag(Tok, diag::err_lambda_missing_parens)
828 << Tok.is(tok::arrow)
829 << FixItHint::CreateInsertion(Tok.getLocation(), "() ");
830 SourceLocation DeclLoc = Tok.getLocation();
831 SourceLocation DeclEndLoc = DeclLoc;
833 // Parse 'mutable', if it's there.
834 SourceLocation MutableLoc;
835 if (Tok.is(tok::kw_mutable)) {
836 MutableLoc = ConsumeToken();
837 DeclEndLoc = MutableLoc;
840 // Parse the return type, if there is one.
841 ParsedType TrailingReturnType;
842 if (Tok.is(tok::arrow)) {
844 TrailingReturnType = ParseTrailingReturnType(Range).get();
845 if (Range.getEnd().isValid())
846 DeclEndLoc = Range.getEnd();
849 ParsedAttributes Attr(AttrFactory);
850 D.AddTypeInfo(DeclaratorChunk::getFunction(/*hasProto=*/true,
851 /*isVariadic=*/false,
852 /*EllipsisLoc=*/SourceLocation(),
853 /*Params=*/0, /*NumParams=*/0,
855 /*RefQualifierIsLValueRef=*/true,
856 /*RefQualifierLoc=*/SourceLocation(),
857 /*ConstQualifierLoc=*/SourceLocation(),
858 /*VolatileQualifierLoc=*/SourceLocation(),
861 /*ESpecLoc=*/SourceLocation(),
863 /*ExceptionRanges=*/0,
866 DeclLoc, DeclEndLoc, D,
872 // FIXME: Rename BlockScope -> ClosureScope if we decide to continue using
874 unsigned ScopeFlags = Scope::BlockScope | Scope::FnScope | Scope::DeclScope;
875 ParseScope BodyScope(this, ScopeFlags);
877 Actions.ActOnStartOfLambdaDefinition(Intro, D, getCurScope());
879 // Parse compound-statement.
880 if (!Tok.is(tok::l_brace)) {
881 Diag(Tok, diag::err_expected_lambda_body);
882 Actions.ActOnLambdaError(LambdaBeginLoc, getCurScope());
886 StmtResult Stmt(ParseCompoundStatementBody());
889 if (!Stmt.isInvalid())
890 return Actions.ActOnLambdaExpr(LambdaBeginLoc, Stmt.take(), getCurScope());
892 Actions.ActOnLambdaError(LambdaBeginLoc, getCurScope());
896 /// ParseCXXCasts - This handles the various ways to cast expressions to another
899 /// postfix-expression: [C++ 5.2p1]
900 /// 'dynamic_cast' '<' type-name '>' '(' expression ')'
901 /// 'static_cast' '<' type-name '>' '(' expression ')'
902 /// 'reinterpret_cast' '<' type-name '>' '(' expression ')'
903 /// 'const_cast' '<' type-name '>' '(' expression ')'
905 ExprResult Parser::ParseCXXCasts() {
906 tok::TokenKind Kind = Tok.getKind();
907 const char *CastName = 0; // For error messages
910 default: llvm_unreachable("Unknown C++ cast!");
911 case tok::kw_const_cast: CastName = "const_cast"; break;
912 case tok::kw_dynamic_cast: CastName = "dynamic_cast"; break;
913 case tok::kw_reinterpret_cast: CastName = "reinterpret_cast"; break;
914 case tok::kw_static_cast: CastName = "static_cast"; break;
917 SourceLocation OpLoc = ConsumeToken();
918 SourceLocation LAngleBracketLoc = Tok.getLocation();
920 // Check for "<::" which is parsed as "[:". If found, fix token stream,
921 // diagnose error, suggest fix, and recover parsing.
922 Token Next = NextToken();
923 if (Tok.is(tok::l_square) && Tok.getLength() == 2 && Next.is(tok::colon) &&
924 AreTokensAdjacent(PP, Tok, Next))
925 FixDigraph(*this, PP, Tok, Next, Kind, /*AtDigraph*/true);
927 if (ExpectAndConsume(tok::less, diag::err_expected_less_after, CastName))
930 // Parse the common declaration-specifiers piece.
931 DeclSpec DS(AttrFactory);
932 ParseSpecifierQualifierList(DS);
934 // Parse the abstract-declarator, if present.
935 Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
936 ParseDeclarator(DeclaratorInfo);
938 SourceLocation RAngleBracketLoc = Tok.getLocation();
940 if (ExpectAndConsume(tok::greater, diag::err_expected_greater))
941 return ExprError(Diag(LAngleBracketLoc, diag::note_matching) << "<");
943 SourceLocation LParenLoc, RParenLoc;
944 BalancedDelimiterTracker T(*this, tok::l_paren);
946 if (T.expectAndConsume(diag::err_expected_lparen_after, CastName))
949 ExprResult Result = ParseExpression();
954 if (!Result.isInvalid() && !DeclaratorInfo.isInvalidType())
955 Result = Actions.ActOnCXXNamedCast(OpLoc, Kind,
956 LAngleBracketLoc, DeclaratorInfo,
958 T.getOpenLocation(), Result.take(),
959 T.getCloseLocation());
964 /// ParseCXXTypeid - This handles the C++ typeid expression.
966 /// postfix-expression: [C++ 5.2p1]
967 /// 'typeid' '(' expression ')'
968 /// 'typeid' '(' type-id ')'
970 ExprResult Parser::ParseCXXTypeid() {
971 assert(Tok.is(tok::kw_typeid) && "Not 'typeid'!");
973 SourceLocation OpLoc = ConsumeToken();
974 SourceLocation LParenLoc, RParenLoc;
975 BalancedDelimiterTracker T(*this, tok::l_paren);
977 // typeid expressions are always parenthesized.
978 if (T.expectAndConsume(diag::err_expected_lparen_after, "typeid"))
980 LParenLoc = T.getOpenLocation();
984 if (isTypeIdInParens()) {
985 TypeResult Ty = ParseTypeName();
989 RParenLoc = T.getCloseLocation();
990 if (Ty.isInvalid() || RParenLoc.isInvalid())
993 Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc, /*isType=*/true,
994 Ty.get().getAsOpaquePtr(), RParenLoc);
996 // C++0x [expr.typeid]p3:
997 // When typeid is applied to an expression other than an lvalue of a
998 // polymorphic class type [...] The expression is an unevaluated
999 // operand (Clause 5).
1001 // Note that we can't tell whether the expression is an lvalue of a
1002 // polymorphic class type until after we've parsed the expression; we
1003 // speculatively assume the subexpression is unevaluated, and fix it up
1005 EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated);
1006 Result = ParseExpression();
1009 if (Result.isInvalid())
1010 SkipUntil(tok::r_paren);
1013 RParenLoc = T.getCloseLocation();
1014 if (RParenLoc.isInvalid())
1017 Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc, /*isType=*/false,
1018 Result.release(), RParenLoc);
1022 return move(Result);
1025 /// ParseCXXUuidof - This handles the Microsoft C++ __uuidof expression.
1027 /// '__uuidof' '(' expression ')'
1028 /// '__uuidof' '(' type-id ')'
1030 ExprResult Parser::ParseCXXUuidof() {
1031 assert(Tok.is(tok::kw___uuidof) && "Not '__uuidof'!");
1033 SourceLocation OpLoc = ConsumeToken();
1034 BalancedDelimiterTracker T(*this, tok::l_paren);
1036 // __uuidof expressions are always parenthesized.
1037 if (T.expectAndConsume(diag::err_expected_lparen_after, "__uuidof"))
1042 if (isTypeIdInParens()) {
1043 TypeResult Ty = ParseTypeName();
1051 Result = Actions.ActOnCXXUuidof(OpLoc, T.getOpenLocation(), /*isType=*/true,
1052 Ty.get().getAsOpaquePtr(),
1053 T.getCloseLocation());
1055 EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated);
1056 Result = ParseExpression();
1059 if (Result.isInvalid())
1060 SkipUntil(tok::r_paren);
1064 Result = Actions.ActOnCXXUuidof(OpLoc, T.getOpenLocation(),
1066 Result.release(), T.getCloseLocation());
1070 return move(Result);
1073 /// \brief Parse a C++ pseudo-destructor expression after the base,
1074 /// . or -> operator, and nested-name-specifier have already been
1077 /// postfix-expression: [C++ 5.2]
1078 /// postfix-expression . pseudo-destructor-name
1079 /// postfix-expression -> pseudo-destructor-name
1081 /// pseudo-destructor-name:
1082 /// ::[opt] nested-name-specifier[opt] type-name :: ~type-name
1083 /// ::[opt] nested-name-specifier template simple-template-id ::
1085 /// ::[opt] nested-name-specifier[opt] ~type-name
1088 Parser::ParseCXXPseudoDestructor(ExprArg Base, SourceLocation OpLoc,
1089 tok::TokenKind OpKind,
1091 ParsedType ObjectType) {
1092 // We're parsing either a pseudo-destructor-name or a dependent
1093 // member access that has the same form as a
1094 // pseudo-destructor-name. We parse both in the same way and let
1095 // the action model sort them out.
1097 // Note that the ::[opt] nested-name-specifier[opt] has already
1098 // been parsed, and if there was a simple-template-id, it has
1099 // been coalesced into a template-id annotation token.
1100 UnqualifiedId FirstTypeName;
1101 SourceLocation CCLoc;
1102 if (Tok.is(tok::identifier)) {
1103 FirstTypeName.setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
1105 assert(Tok.is(tok::coloncolon) &&"ParseOptionalCXXScopeSpecifier fail");
1106 CCLoc = ConsumeToken();
1107 } else if (Tok.is(tok::annot_template_id)) {
1108 // FIXME: retrieve TemplateKWLoc from template-id annotation and
1109 // store it in the pseudo-dtor node (to be used when instantiating it).
1110 FirstTypeName.setTemplateId(
1111 (TemplateIdAnnotation *)Tok.getAnnotationValue());
1113 assert(Tok.is(tok::coloncolon) &&"ParseOptionalCXXScopeSpecifier fail");
1114 CCLoc = ConsumeToken();
1116 FirstTypeName.setIdentifier(0, SourceLocation());
1120 assert(Tok.is(tok::tilde) && "ParseOptionalCXXScopeSpecifier fail");
1121 SourceLocation TildeLoc = ConsumeToken();
1123 if (Tok.is(tok::kw_decltype) && !FirstTypeName.isValid() && SS.isEmpty()) {
1124 DeclSpec DS(AttrFactory);
1125 ParseDecltypeSpecifier(DS);
1126 if (DS.getTypeSpecType() == TST_error)
1128 return Actions.ActOnPseudoDestructorExpr(getCurScope(), Base, OpLoc,
1129 OpKind, TildeLoc, DS,
1130 Tok.is(tok::l_paren));
1133 if (!Tok.is(tok::identifier)) {
1134 Diag(Tok, diag::err_destructor_tilde_identifier);
1138 // Parse the second type.
1139 UnqualifiedId SecondTypeName;
1140 IdentifierInfo *Name = Tok.getIdentifierInfo();
1141 SourceLocation NameLoc = ConsumeToken();
1142 SecondTypeName.setIdentifier(Name, NameLoc);
1144 // If there is a '<', the second type name is a template-id. Parse
1146 if (Tok.is(tok::less) &&
1147 ParseUnqualifiedIdTemplateId(SS, SourceLocation(),
1149 false, ObjectType, SecondTypeName,
1150 /*AssumeTemplateName=*/true))
1153 return Actions.ActOnPseudoDestructorExpr(getCurScope(), Base,
1155 SS, FirstTypeName, CCLoc,
1156 TildeLoc, SecondTypeName,
1157 Tok.is(tok::l_paren));
1160 /// ParseCXXBoolLiteral - This handles the C++ Boolean literals.
1162 /// boolean-literal: [C++ 2.13.5]
1165 ExprResult Parser::ParseCXXBoolLiteral() {
1166 tok::TokenKind Kind = Tok.getKind();
1167 return Actions.ActOnCXXBoolLiteral(ConsumeToken(), Kind);
1170 /// ParseThrowExpression - This handles the C++ throw expression.
1172 /// throw-expression: [C++ 15]
1173 /// 'throw' assignment-expression[opt]
1174 ExprResult Parser::ParseThrowExpression() {
1175 assert(Tok.is(tok::kw_throw) && "Not throw!");
1176 SourceLocation ThrowLoc = ConsumeToken(); // Eat the throw token.
1178 // If the current token isn't the start of an assignment-expression,
1179 // then the expression is not present. This handles things like:
1180 // "C ? throw : (void)42", which is crazy but legal.
1181 switch (Tok.getKind()) { // FIXME: move this predicate somewhere common.
1188 return Actions.ActOnCXXThrow(getCurScope(), ThrowLoc, 0);
1191 ExprResult Expr(ParseAssignmentExpression());
1192 if (Expr.isInvalid()) return move(Expr);
1193 return Actions.ActOnCXXThrow(getCurScope(), ThrowLoc, Expr.take());
1197 /// ParseCXXThis - This handles the C++ 'this' pointer.
1199 /// C++ 9.3.2: In the body of a non-static member function, the keyword this is
1200 /// a non-lvalue expression whose value is the address of the object for which
1201 /// the function is called.
1202 ExprResult Parser::ParseCXXThis() {
1203 assert(Tok.is(tok::kw_this) && "Not 'this'!");
1204 SourceLocation ThisLoc = ConsumeToken();
1205 return Actions.ActOnCXXThis(ThisLoc);
1208 /// ParseCXXTypeConstructExpression - Parse construction of a specified type.
1209 /// Can be interpreted either as function-style casting ("int(x)")
1210 /// or class type construction ("ClassType(x,y,z)")
1211 /// or creation of a value-initialized type ("int()").
1212 /// See [C++ 5.2.3].
1214 /// postfix-expression: [C++ 5.2p1]
1215 /// simple-type-specifier '(' expression-list[opt] ')'
1216 /// [C++0x] simple-type-specifier braced-init-list
1217 /// typename-specifier '(' expression-list[opt] ')'
1218 /// [C++0x] typename-specifier braced-init-list
1221 Parser::ParseCXXTypeConstructExpression(const DeclSpec &DS) {
1222 Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
1223 ParsedType TypeRep = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo).get();
1225 assert((Tok.is(tok::l_paren) ||
1226 (getLangOpts().CPlusPlus0x && Tok.is(tok::l_brace)))
1227 && "Expected '(' or '{'!");
1229 if (Tok.is(tok::l_brace)) {
1230 ExprResult Init = ParseBraceInitializer();
1231 if (Init.isInvalid())
1233 Expr *InitList = Init.take();
1234 return Actions.ActOnCXXTypeConstructExpr(TypeRep, SourceLocation(),
1235 MultiExprArg(&InitList, 1),
1238 GreaterThanIsOperatorScope G(GreaterThanIsOperator, true);
1240 BalancedDelimiterTracker T(*this, tok::l_paren);
1243 ExprVector Exprs(Actions);
1244 CommaLocsTy CommaLocs;
1246 if (Tok.isNot(tok::r_paren)) {
1247 if (ParseExpressionList(Exprs, CommaLocs)) {
1248 SkipUntil(tok::r_paren);
1256 // TypeRep could be null, if it references an invalid typedef.
1260 assert((Exprs.size() == 0 || Exprs.size()-1 == CommaLocs.size())&&
1261 "Unexpected number of commas!");
1262 return Actions.ActOnCXXTypeConstructExpr(TypeRep, T.getOpenLocation(),
1264 T.getCloseLocation());
1268 /// ParseCXXCondition - if/switch/while condition expression.
1272 /// type-specifier-seq declarator '=' assignment-expression
1273 /// [C++11] type-specifier-seq declarator '=' initializer-clause
1274 /// [C++11] type-specifier-seq declarator braced-init-list
1275 /// [GNU] type-specifier-seq declarator simple-asm-expr[opt] attributes[opt]
1276 /// '=' assignment-expression
1278 /// \param ExprResult if the condition was parsed as an expression, the
1279 /// parsed expression.
1281 /// \param DeclResult if the condition was parsed as a declaration, the
1282 /// parsed declaration.
1284 /// \param Loc The location of the start of the statement that requires this
1285 /// condition, e.g., the "for" in a for loop.
1287 /// \param ConvertToBoolean Whether the condition expression should be
1288 /// converted to a boolean value.
1290 /// \returns true if there was a parsing, false otherwise.
1291 bool Parser::ParseCXXCondition(ExprResult &ExprOut,
1294 bool ConvertToBoolean) {
1295 if (Tok.is(tok::code_completion)) {
1296 Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Condition);
1301 if (!isCXXConditionDeclaration()) {
1302 // Parse the expression.
1303 ExprOut = ParseExpression(); // expression
1305 if (ExprOut.isInvalid())
1308 // If required, convert to a boolean value.
1309 if (ConvertToBoolean)
1311 = Actions.ActOnBooleanCondition(getCurScope(), Loc, ExprOut.get());
1312 return ExprOut.isInvalid();
1315 // type-specifier-seq
1316 DeclSpec DS(AttrFactory);
1317 ParseSpecifierQualifierList(DS);
1320 Declarator DeclaratorInfo(DS, Declarator::ConditionContext);
1321 ParseDeclarator(DeclaratorInfo);
1323 // simple-asm-expr[opt]
1324 if (Tok.is(tok::kw_asm)) {
1326 ExprResult AsmLabel(ParseSimpleAsm(&Loc));
1327 if (AsmLabel.isInvalid()) {
1328 SkipUntil(tok::semi);
1331 DeclaratorInfo.setAsmLabel(AsmLabel.release());
1332 DeclaratorInfo.SetRangeEnd(Loc);
1335 // If attributes are present, parse them.
1336 MaybeParseGNUAttributes(DeclaratorInfo);
1338 // Type-check the declaration itself.
1339 DeclResult Dcl = Actions.ActOnCXXConditionDeclaration(getCurScope(),
1341 DeclOut = Dcl.get();
1342 ExprOut = ExprError();
1344 // '=' assignment-expression
1345 // If a '==' or '+=' is found, suggest a fixit to '='.
1346 bool CopyInitialization = isTokenEqualOrEqualTypo();
1347 if (CopyInitialization)
1350 ExprResult InitExpr = ExprError();
1351 if (getLangOpts().CPlusPlus0x && Tok.is(tok::l_brace)) {
1352 Diag(Tok.getLocation(),
1353 diag::warn_cxx98_compat_generalized_initializer_lists);
1354 InitExpr = ParseBraceInitializer();
1355 } else if (CopyInitialization) {
1356 InitExpr = ParseAssignmentExpression();
1357 } else if (Tok.is(tok::l_paren)) {
1358 // This was probably an attempt to initialize the variable.
1359 SourceLocation LParen = ConsumeParen(), RParen = LParen;
1360 if (SkipUntil(tok::r_paren, true, /*DontConsume=*/true))
1361 RParen = ConsumeParen();
1362 Diag(DeclOut ? DeclOut->getLocation() : LParen,
1363 diag::err_expected_init_in_condition_lparen)
1364 << SourceRange(LParen, RParen);
1366 Diag(DeclOut ? DeclOut->getLocation() : Tok.getLocation(),
1367 diag::err_expected_init_in_condition);
1370 if (!InitExpr.isInvalid())
1371 Actions.AddInitializerToDecl(DeclOut, InitExpr.take(), !CopyInitialization,
1372 DS.getTypeSpecType() == DeclSpec::TST_auto);
1374 // FIXME: Build a reference to this declaration? Convert it to bool?
1375 // (This is currently handled by Sema).
1377 Actions.FinalizeDeclaration(DeclOut);
1382 /// \brief Determine whether the current token starts a C++
1383 /// simple-type-specifier.
1384 bool Parser::isCXXSimpleTypeSpecifier() const {
1385 switch (Tok.getKind()) {
1386 case tok::annot_typename:
1389 case tok::kw___int64:
1390 case tok::kw___int128:
1391 case tok::kw_signed:
1392 case tok::kw_unsigned:
1398 case tok::kw_double:
1399 case tok::kw_wchar_t:
1400 case tok::kw_char16_t:
1401 case tok::kw_char32_t:
1403 case tok::kw_decltype:
1404 case tok::kw_typeof:
1405 case tok::kw___underlying_type:
1415 /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers.
1416 /// This should only be called when the current token is known to be part of
1417 /// simple-type-specifier.
1419 /// simple-type-specifier:
1420 /// '::'[opt] nested-name-specifier[opt] type-name
1421 /// '::'[opt] nested-name-specifier 'template' simple-template-id [TODO]
1433 /// [GNU] typeof-specifier
1434 /// [C++0x] auto [TODO]
1441 void Parser::ParseCXXSimpleTypeSpecifier(DeclSpec &DS) {
1442 DS.SetRangeStart(Tok.getLocation());
1443 const char *PrevSpec;
1445 SourceLocation Loc = Tok.getLocation();
1447 switch (Tok.getKind()) {
1448 case tok::identifier: // foo::bar
1449 case tok::coloncolon: // ::foo::bar
1450 llvm_unreachable("Annotation token should already be formed!");
1452 llvm_unreachable("Not a simple-type-specifier token!");
1455 case tok::annot_typename: {
1456 if (getTypeAnnotation(Tok))
1457 DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, DiagID,
1458 getTypeAnnotation(Tok));
1460 DS.SetTypeSpecError();
1462 DS.SetRangeEnd(Tok.getAnnotationEndLoc());
1465 // Objective-C supports syntax of the form 'id<proto1,proto2>' where 'id'
1466 // is a specific typedef and 'itf<proto1,proto2>' where 'itf' is an
1467 // Objective-C interface. If we don't have Objective-C or a '<', this is
1468 // just a normal reference to a typedef name.
1469 if (Tok.is(tok::less) && getLangOpts().ObjC1)
1470 ParseObjCProtocolQualifiers(DS);
1472 DS.Finish(Diags, PP);
1478 DS.SetTypeSpecWidth(DeclSpec::TSW_short, Loc, PrevSpec, DiagID);
1481 DS.SetTypeSpecWidth(DeclSpec::TSW_long, Loc, PrevSpec, DiagID);
1483 case tok::kw___int64:
1484 DS.SetTypeSpecWidth(DeclSpec::TSW_longlong, Loc, PrevSpec, DiagID);
1486 case tok::kw_signed:
1487 DS.SetTypeSpecSign(DeclSpec::TSS_signed, Loc, PrevSpec, DiagID);
1489 case tok::kw_unsigned:
1490 DS.SetTypeSpecSign(DeclSpec::TSS_unsigned, Loc, PrevSpec, DiagID);
1493 DS.SetTypeSpecType(DeclSpec::TST_void, Loc, PrevSpec, DiagID);
1496 DS.SetTypeSpecType(DeclSpec::TST_char, Loc, PrevSpec, DiagID);
1499 DS.SetTypeSpecType(DeclSpec::TST_int, Loc, PrevSpec, DiagID);
1501 case tok::kw___int128:
1502 DS.SetTypeSpecType(DeclSpec::TST_int128, Loc, PrevSpec, DiagID);
1505 DS.SetTypeSpecType(DeclSpec::TST_half, Loc, PrevSpec, DiagID);
1508 DS.SetTypeSpecType(DeclSpec::TST_float, Loc, PrevSpec, DiagID);
1510 case tok::kw_double:
1511 DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec, DiagID);
1513 case tok::kw_wchar_t:
1514 DS.SetTypeSpecType(DeclSpec::TST_wchar, Loc, PrevSpec, DiagID);
1516 case tok::kw_char16_t:
1517 DS.SetTypeSpecType(DeclSpec::TST_char16, Loc, PrevSpec, DiagID);
1519 case tok::kw_char32_t:
1520 DS.SetTypeSpecType(DeclSpec::TST_char32, Loc, PrevSpec, DiagID);
1523 DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec, DiagID);
1525 case tok::annot_decltype:
1526 case tok::kw_decltype:
1527 DS.SetRangeEnd(ParseDecltypeSpecifier(DS));
1528 return DS.Finish(Diags, PP);
1530 // GNU typeof support.
1531 case tok::kw_typeof:
1532 ParseTypeofSpecifier(DS);
1533 DS.Finish(Diags, PP);
1536 if (Tok.is(tok::annot_typename))
1537 DS.SetRangeEnd(Tok.getAnnotationEndLoc());
1539 DS.SetRangeEnd(Tok.getLocation());
1541 DS.Finish(Diags, PP);
1544 /// ParseCXXTypeSpecifierSeq - Parse a C++ type-specifier-seq (C++
1545 /// [dcl.name]), which is a non-empty sequence of type-specifiers,
1546 /// e.g., "const short int". Note that the DeclSpec is *not* finished
1547 /// by parsing the type-specifier-seq, because these sequences are
1548 /// typically followed by some form of declarator. Returns true and
1549 /// emits diagnostics if this is not a type-specifier-seq, false
1552 /// type-specifier-seq: [C++ 8.1]
1553 /// type-specifier type-specifier-seq[opt]
1555 bool Parser::ParseCXXTypeSpecifierSeq(DeclSpec &DS) {
1556 ParseSpecifierQualifierList(DS, AS_none, DSC_type_specifier);
1557 DS.Finish(Diags, PP);
1561 /// \brief Finish parsing a C++ unqualified-id that is a template-id of
1564 /// This routine is invoked when a '<' is encountered after an identifier or
1565 /// operator-function-id is parsed by \c ParseUnqualifiedId() to determine
1566 /// whether the unqualified-id is actually a template-id. This routine will
1567 /// then parse the template arguments and form the appropriate template-id to
1568 /// return to the caller.
1570 /// \param SS the nested-name-specifier that precedes this template-id, if
1571 /// we're actually parsing a qualified-id.
1573 /// \param Name for constructor and destructor names, this is the actual
1574 /// identifier that may be a template-name.
1576 /// \param NameLoc the location of the class-name in a constructor or
1579 /// \param EnteringContext whether we're entering the scope of the
1580 /// nested-name-specifier.
1582 /// \param ObjectType if this unqualified-id occurs within a member access
1583 /// expression, the type of the base object whose member is being accessed.
1585 /// \param Id as input, describes the template-name or operator-function-id
1586 /// that precedes the '<'. If template arguments were parsed successfully,
1587 /// will be updated with the template-id.
1589 /// \param AssumeTemplateId When true, this routine will assume that the name
1590 /// refers to a template without performing name lookup to verify.
1592 /// \returns true if a parse error occurred, false otherwise.
1593 bool Parser::ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS,
1594 SourceLocation TemplateKWLoc,
1595 IdentifierInfo *Name,
1596 SourceLocation NameLoc,
1597 bool EnteringContext,
1598 ParsedType ObjectType,
1600 bool AssumeTemplateId) {
1601 assert((AssumeTemplateId || Tok.is(tok::less)) &&
1602 "Expected '<' to finish parsing a template-id");
1604 TemplateTy Template;
1605 TemplateNameKind TNK = TNK_Non_template;
1606 switch (Id.getKind()) {
1607 case UnqualifiedId::IK_Identifier:
1608 case UnqualifiedId::IK_OperatorFunctionId:
1609 case UnqualifiedId::IK_LiteralOperatorId:
1610 if (AssumeTemplateId) {
1611 TNK = Actions.ActOnDependentTemplateName(getCurScope(), SS, TemplateKWLoc,
1612 Id, ObjectType, EnteringContext,
1614 if (TNK == TNK_Non_template)
1617 bool MemberOfUnknownSpecialization;
1618 TNK = Actions.isTemplateName(getCurScope(), SS,
1619 TemplateKWLoc.isValid(), Id,
1620 ObjectType, EnteringContext, Template,
1621 MemberOfUnknownSpecialization);
1623 if (TNK == TNK_Non_template && MemberOfUnknownSpecialization &&
1624 ObjectType && IsTemplateArgumentList()) {
1625 // We have something like t->getAs<T>(), where getAs is a
1626 // member of an unknown specialization. However, this will only
1627 // parse correctly as a template, so suggest the keyword 'template'
1628 // before 'getAs' and treat this as a dependent template name.
1630 if (Id.getKind() == UnqualifiedId::IK_Identifier)
1631 Name = Id.Identifier->getName();
1634 if (Id.getKind() == UnqualifiedId::IK_OperatorFunctionId)
1635 Name += getOperatorSpelling(Id.OperatorFunctionId.Operator);
1637 Name += Id.Identifier->getName();
1639 Diag(Id.StartLocation, diag::err_missing_dependent_template_keyword)
1641 << FixItHint::CreateInsertion(Id.StartLocation, "template ");
1642 TNK = Actions.ActOnDependentTemplateName(getCurScope(),
1643 SS, TemplateKWLoc, Id,
1644 ObjectType, EnteringContext,
1646 if (TNK == TNK_Non_template)
1652 case UnqualifiedId::IK_ConstructorName: {
1653 UnqualifiedId TemplateName;
1654 bool MemberOfUnknownSpecialization;
1655 TemplateName.setIdentifier(Name, NameLoc);
1656 TNK = Actions.isTemplateName(getCurScope(), SS, TemplateKWLoc.isValid(),
1657 TemplateName, ObjectType,
1658 EnteringContext, Template,
1659 MemberOfUnknownSpecialization);
1663 case UnqualifiedId::IK_DestructorName: {
1664 UnqualifiedId TemplateName;
1665 bool MemberOfUnknownSpecialization;
1666 TemplateName.setIdentifier(Name, NameLoc);
1668 TNK = Actions.ActOnDependentTemplateName(getCurScope(),
1669 SS, TemplateKWLoc, TemplateName,
1670 ObjectType, EnteringContext,
1672 if (TNK == TNK_Non_template)
1675 TNK = Actions.isTemplateName(getCurScope(), SS, TemplateKWLoc.isValid(),
1676 TemplateName, ObjectType,
1677 EnteringContext, Template,
1678 MemberOfUnknownSpecialization);
1680 if (TNK == TNK_Non_template && !Id.DestructorName.get()) {
1681 Diag(NameLoc, diag::err_destructor_template_id)
1682 << Name << SS.getRange();
1693 if (TNK == TNK_Non_template)
1696 // Parse the enclosed template argument list.
1697 SourceLocation LAngleLoc, RAngleLoc;
1698 TemplateArgList TemplateArgs;
1699 if (Tok.is(tok::less) &&
1700 ParseTemplateIdAfterTemplateName(Template, Id.StartLocation,
1701 SS, true, LAngleLoc,
1706 if (Id.getKind() == UnqualifiedId::IK_Identifier ||
1707 Id.getKind() == UnqualifiedId::IK_OperatorFunctionId ||
1708 Id.getKind() == UnqualifiedId::IK_LiteralOperatorId) {
1709 // Form a parsed representation of the template-id to be stored in the
1711 TemplateIdAnnotation *TemplateId
1712 = TemplateIdAnnotation::Allocate(TemplateArgs.size(), TemplateIds);
1714 if (Id.getKind() == UnqualifiedId::IK_Identifier) {
1715 TemplateId->Name = Id.Identifier;
1716 TemplateId->Operator = OO_None;
1717 TemplateId->TemplateNameLoc = Id.StartLocation;
1719 TemplateId->Name = 0;
1720 TemplateId->Operator = Id.OperatorFunctionId.Operator;
1721 TemplateId->TemplateNameLoc = Id.StartLocation;
1724 TemplateId->SS = SS;
1725 TemplateId->TemplateKWLoc = TemplateKWLoc;
1726 TemplateId->Template = Template;
1727 TemplateId->Kind = TNK;
1728 TemplateId->LAngleLoc = LAngleLoc;
1729 TemplateId->RAngleLoc = RAngleLoc;
1730 ParsedTemplateArgument *Args = TemplateId->getTemplateArgs();
1731 for (unsigned Arg = 0, ArgEnd = TemplateArgs.size();
1732 Arg != ArgEnd; ++Arg)
1733 Args[Arg] = TemplateArgs[Arg];
1735 Id.setTemplateId(TemplateId);
1739 // Bundle the template arguments together.
1740 ASTTemplateArgsPtr TemplateArgsPtr(Actions, TemplateArgs.data(),
1741 TemplateArgs.size());
1743 // Constructor and destructor names.
1745 = Actions.ActOnTemplateIdType(SS, TemplateKWLoc,
1747 LAngleLoc, TemplateArgsPtr, RAngleLoc,
1748 /*IsCtorOrDtorName=*/true);
1749 if (Type.isInvalid())
1752 if (Id.getKind() == UnqualifiedId::IK_ConstructorName)
1753 Id.setConstructorName(Type.get(), NameLoc, RAngleLoc);
1755 Id.setDestructorName(Id.StartLocation, Type.get(), RAngleLoc);
1760 /// \brief Parse an operator-function-id or conversion-function-id as part
1761 /// of a C++ unqualified-id.
1763 /// This routine is responsible only for parsing the operator-function-id or
1764 /// conversion-function-id; it does not handle template arguments in any way.
1767 /// operator-function-id: [C++ 13.5]
1768 /// 'operator' operator
1770 /// operator: one of
1771 /// new delete new[] delete[]
1772 /// + - * / % ^ & | ~
1773 /// ! = < > += -= *= /= %=
1774 /// ^= &= |= << >> >>= <<= == !=
1775 /// <= >= && || ++ -- , ->* ->
1778 /// conversion-function-id: [C++ 12.3.2]
1779 /// operator conversion-type-id
1781 /// conversion-type-id:
1782 /// type-specifier-seq conversion-declarator[opt]
1784 /// conversion-declarator:
1785 /// ptr-operator conversion-declarator[opt]
1788 /// \param The nested-name-specifier that preceded this unqualified-id. If
1789 /// non-empty, then we are parsing the unqualified-id of a qualified-id.
1791 /// \param EnteringContext whether we are entering the scope of the
1792 /// nested-name-specifier.
1794 /// \param ObjectType if this unqualified-id occurs within a member access
1795 /// expression, the type of the base object whose member is being accessed.
1797 /// \param Result on a successful parse, contains the parsed unqualified-id.
1799 /// \returns true if parsing fails, false otherwise.
1800 bool Parser::ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext,
1801 ParsedType ObjectType,
1802 UnqualifiedId &Result) {
1803 assert(Tok.is(tok::kw_operator) && "Expected 'operator' keyword");
1805 // Consume the 'operator' keyword.
1806 SourceLocation KeywordLoc = ConsumeToken();
1808 // Determine what kind of operator name we have.
1809 unsigned SymbolIdx = 0;
1810 SourceLocation SymbolLocations[3];
1811 OverloadedOperatorKind Op = OO_None;
1812 switch (Tok.getKind()) {
1814 case tok::kw_delete: {
1815 bool isNew = Tok.getKind() == tok::kw_new;
1816 // Consume the 'new' or 'delete'.
1817 SymbolLocations[SymbolIdx++] = ConsumeToken();
1818 // Check for array new/delete.
1819 if (Tok.is(tok::l_square) &&
1820 (!getLangOpts().CPlusPlus0x || NextToken().isNot(tok::l_square))) {
1821 // Consume the '[' and ']'.
1822 BalancedDelimiterTracker T(*this, tok::l_square);
1825 if (T.getCloseLocation().isInvalid())
1828 SymbolLocations[SymbolIdx++] = T.getOpenLocation();
1829 SymbolLocations[SymbolIdx++] = T.getCloseLocation();
1830 Op = isNew? OO_Array_New : OO_Array_Delete;
1832 Op = isNew? OO_New : OO_Delete;
1837 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
1839 SymbolLocations[SymbolIdx++] = ConsumeToken(); \
1842 #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
1843 #include "clang/Basic/OperatorKinds.def"
1845 case tok::l_paren: {
1846 // Consume the '(' and ')'.
1847 BalancedDelimiterTracker T(*this, tok::l_paren);
1850 if (T.getCloseLocation().isInvalid())
1853 SymbolLocations[SymbolIdx++] = T.getOpenLocation();
1854 SymbolLocations[SymbolIdx++] = T.getCloseLocation();
1859 case tok::l_square: {
1860 // Consume the '[' and ']'.
1861 BalancedDelimiterTracker T(*this, tok::l_square);
1864 if (T.getCloseLocation().isInvalid())
1867 SymbolLocations[SymbolIdx++] = T.getOpenLocation();
1868 SymbolLocations[SymbolIdx++] = T.getCloseLocation();
1873 case tok::code_completion: {
1874 // Code completion for the operator name.
1875 Actions.CodeCompleteOperatorName(getCurScope());
1877 // Don't try to parse any further.
1885 if (Op != OO_None) {
1886 // We have parsed an operator-function-id.
1887 Result.setOperatorFunctionId(KeywordLoc, Op, SymbolLocations);
1891 // Parse a literal-operator-id.
1893 // literal-operator-id: [C++0x 13.5.8]
1894 // operator "" identifier
1896 if (getLangOpts().CPlusPlus0x && isTokenStringLiteral()) {
1897 Diag(Tok.getLocation(), diag::warn_cxx98_compat_literal_operator);
1899 SourceLocation DiagLoc;
1900 unsigned DiagId = 0;
1902 // We're past translation phase 6, so perform string literal concatenation
1903 // before checking for "".
1904 llvm::SmallVector<Token, 4> Toks;
1905 llvm::SmallVector<SourceLocation, 4> TokLocs;
1906 while (isTokenStringLiteral()) {
1907 if (!Tok.is(tok::string_literal) && !DiagId) {
1908 DiagLoc = Tok.getLocation();
1909 DiagId = diag::err_literal_operator_string_prefix;
1911 Toks.push_back(Tok);
1912 TokLocs.push_back(ConsumeStringToken());
1915 StringLiteralParser Literal(Toks.data(), Toks.size(), PP);
1916 if (Literal.hadError)
1919 // Grab the literal operator's suffix, which will be either the next token
1920 // or a ud-suffix from the string literal.
1921 IdentifierInfo *II = 0;
1922 SourceLocation SuffixLoc;
1923 if (!Literal.getUDSuffix().empty()) {
1924 II = &PP.getIdentifierTable().get(Literal.getUDSuffix());
1926 Lexer::AdvanceToTokenCharacter(TokLocs[Literal.getUDSuffixToken()],
1927 Literal.getUDSuffixOffset(),
1928 PP.getSourceManager(), getLangOpts());
1929 // This form is not permitted by the standard (yet).
1930 DiagLoc = SuffixLoc;
1931 DiagId = diag::err_literal_operator_missing_space;
1932 } else if (Tok.is(tok::identifier)) {
1933 II = Tok.getIdentifierInfo();
1934 SuffixLoc = ConsumeToken();
1935 TokLocs.push_back(SuffixLoc);
1937 Diag(Tok.getLocation(), diag::err_expected_ident);
1941 // The string literal must be empty.
1942 if (!Literal.GetString().empty() || Literal.Pascal) {
1943 DiagLoc = TokLocs.front();
1944 DiagId = diag::err_literal_operator_string_not_empty;
1948 // This isn't a valid literal-operator-id, but we think we know
1949 // what the user meant. Tell them what they should have written.
1950 llvm::SmallString<32> Str;
1952 Str += II->getName();
1953 Diag(DiagLoc, DiagId) << FixItHint::CreateReplacement(
1954 SourceRange(TokLocs.front(), TokLocs.back()), Str);
1957 Result.setLiteralOperatorId(II, KeywordLoc, SuffixLoc);
1961 // Parse a conversion-function-id.
1963 // conversion-function-id: [C++ 12.3.2]
1964 // operator conversion-type-id
1966 // conversion-type-id:
1967 // type-specifier-seq conversion-declarator[opt]
1969 // conversion-declarator:
1970 // ptr-operator conversion-declarator[opt]
1972 // Parse the type-specifier-seq.
1973 DeclSpec DS(AttrFactory);
1974 if (ParseCXXTypeSpecifierSeq(DS)) // FIXME: ObjectType?
1977 // Parse the conversion-declarator, which is merely a sequence of
1979 Declarator D(DS, Declarator::TypeNameContext);
1980 ParseDeclaratorInternal(D, /*DirectDeclParser=*/0);
1982 // Finish up the type.
1983 TypeResult Ty = Actions.ActOnTypeName(getCurScope(), D);
1987 // Note that this is a conversion-function-id.
1988 Result.setConversionFunctionId(KeywordLoc, Ty.get(),
1989 D.getSourceRange().getEnd());
1993 /// \brief Parse a C++ unqualified-id (or a C identifier), which describes the
1994 /// name of an entity.
1997 /// unqualified-id: [C++ expr.prim.general]
1999 /// operator-function-id
2000 /// conversion-function-id
2001 /// [C++0x] literal-operator-id [TODO]
2007 /// \param The nested-name-specifier that preceded this unqualified-id. If
2008 /// non-empty, then we are parsing the unqualified-id of a qualified-id.
2010 /// \param EnteringContext whether we are entering the scope of the
2011 /// nested-name-specifier.
2013 /// \param AllowDestructorName whether we allow parsing of a destructor name.
2015 /// \param AllowConstructorName whether we allow parsing a constructor name.
2017 /// \param ObjectType if this unqualified-id occurs within a member access
2018 /// expression, the type of the base object whose member is being accessed.
2020 /// \param Result on a successful parse, contains the parsed unqualified-id.
2022 /// \returns true if parsing fails, false otherwise.
2023 bool Parser::ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext,
2024 bool AllowDestructorName,
2025 bool AllowConstructorName,
2026 ParsedType ObjectType,
2027 SourceLocation& TemplateKWLoc,
2028 UnqualifiedId &Result) {
2030 // Handle 'A::template B'. This is for template-ids which have not
2031 // already been annotated by ParseOptionalCXXScopeSpecifier().
2032 bool TemplateSpecified = false;
2033 if (getLangOpts().CPlusPlus && Tok.is(tok::kw_template) &&
2034 (ObjectType || SS.isSet())) {
2035 TemplateSpecified = true;
2036 TemplateKWLoc = ConsumeToken();
2041 // template-id (when it hasn't already been annotated)
2042 if (Tok.is(tok::identifier)) {
2043 // Consume the identifier.
2044 IdentifierInfo *Id = Tok.getIdentifierInfo();
2045 SourceLocation IdLoc = ConsumeToken();
2047 if (!getLangOpts().CPlusPlus) {
2048 // If we're not in C++, only identifiers matter. Record the
2049 // identifier and return.
2050 Result.setIdentifier(Id, IdLoc);
2054 if (AllowConstructorName &&
2055 Actions.isCurrentClassName(*Id, getCurScope(), &SS)) {
2056 // We have parsed a constructor name.
2057 ParsedType Ty = Actions.getTypeName(*Id, IdLoc, getCurScope(),
2060 /*IsCtorOrDtorName=*/true,
2061 /*NonTrivialTypeSourceInfo=*/true);
2062 Result.setConstructorName(Ty, IdLoc, IdLoc);
2064 // We have parsed an identifier.
2065 Result.setIdentifier(Id, IdLoc);
2068 // If the next token is a '<', we may have a template.
2069 if (TemplateSpecified || Tok.is(tok::less))
2070 return ParseUnqualifiedIdTemplateId(SS, TemplateKWLoc, Id, IdLoc,
2071 EnteringContext, ObjectType,
2072 Result, TemplateSpecified);
2078 // template-id (already parsed and annotated)
2079 if (Tok.is(tok::annot_template_id)) {
2080 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
2082 // If the template-name names the current class, then this is a constructor
2083 if (AllowConstructorName && TemplateId->Name &&
2084 Actions.isCurrentClassName(*TemplateId->Name, getCurScope(), &SS)) {
2086 // C++ [class.qual]p2 specifies that a qualified template-name
2087 // is taken as the constructor name where a constructor can be
2088 // declared. Thus, the template arguments are extraneous, so
2089 // complain about them and remove them entirely.
2090 Diag(TemplateId->TemplateNameLoc,
2091 diag::err_out_of_line_constructor_template_id)
2093 << FixItHint::CreateRemoval(
2094 SourceRange(TemplateId->LAngleLoc, TemplateId->RAngleLoc));
2095 ParsedType Ty = Actions.getTypeName(*TemplateId->Name,
2096 TemplateId->TemplateNameLoc,
2100 /*IsCtorOrDtorName=*/true,
2101 /*NontrivialTypeSourceInfo=*/true);
2102 Result.setConstructorName(Ty, TemplateId->TemplateNameLoc,
2103 TemplateId->RAngleLoc);
2108 Result.setConstructorTemplateId(TemplateId);
2113 // We have already parsed a template-id; consume the annotation token as
2114 // our unqualified-id.
2115 Result.setTemplateId(TemplateId);
2116 TemplateKWLoc = TemplateId->TemplateKWLoc;
2122 // operator-function-id
2123 // conversion-function-id
2124 if (Tok.is(tok::kw_operator)) {
2125 if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType, Result))
2128 // If we have an operator-function-id or a literal-operator-id and the next
2129 // token is a '<', we may have a
2132 // operator-function-id < template-argument-list[opt] >
2133 if ((Result.getKind() == UnqualifiedId::IK_OperatorFunctionId ||
2134 Result.getKind() == UnqualifiedId::IK_LiteralOperatorId) &&
2135 (TemplateSpecified || Tok.is(tok::less)))
2136 return ParseUnqualifiedIdTemplateId(SS, TemplateKWLoc,
2137 0, SourceLocation(),
2138 EnteringContext, ObjectType,
2139 Result, TemplateSpecified);
2144 if (getLangOpts().CPlusPlus &&
2145 (AllowDestructorName || SS.isSet()) && Tok.is(tok::tilde)) {
2146 // C++ [expr.unary.op]p10:
2147 // There is an ambiguity in the unary-expression ~X(), where X is a
2148 // class-name. The ambiguity is resolved in favor of treating ~ as a
2149 // unary complement rather than treating ~X as referring to a destructor.
2152 SourceLocation TildeLoc = ConsumeToken();
2154 if (SS.isEmpty() && Tok.is(tok::kw_decltype)) {
2155 DeclSpec DS(AttrFactory);
2156 SourceLocation EndLoc = ParseDecltypeSpecifier(DS);
2157 if (ParsedType Type = Actions.getDestructorType(DS, ObjectType)) {
2158 Result.setDestructorName(TildeLoc, Type, EndLoc);
2164 // Parse the class-name.
2165 if (Tok.isNot(tok::identifier)) {
2166 Diag(Tok, diag::err_destructor_tilde_identifier);
2170 // Parse the class-name (or template-name in a simple-template-id).
2171 IdentifierInfo *ClassName = Tok.getIdentifierInfo();
2172 SourceLocation ClassNameLoc = ConsumeToken();
2174 if (TemplateSpecified || Tok.is(tok::less)) {
2175 Result.setDestructorName(TildeLoc, ParsedType(), ClassNameLoc);
2176 return ParseUnqualifiedIdTemplateId(SS, TemplateKWLoc,
2177 ClassName, ClassNameLoc,
2178 EnteringContext, ObjectType,
2179 Result, TemplateSpecified);
2182 // Note that this is a destructor name.
2183 ParsedType Ty = Actions.getDestructorName(TildeLoc, *ClassName,
2184 ClassNameLoc, getCurScope(),
2190 Result.setDestructorName(TildeLoc, Ty, ClassNameLoc);
2194 Diag(Tok, diag::err_expected_unqualified_id)
2195 << getLangOpts().CPlusPlus;
2199 /// ParseCXXNewExpression - Parse a C++ new-expression. New is used to allocate
2200 /// memory in a typesafe manner and call constructors.
2202 /// This method is called to parse the new expression after the optional :: has
2203 /// been already parsed. If the :: was present, "UseGlobal" is true and "Start"
2204 /// is its location. Otherwise, "Start" is the location of the 'new' token.
2207 /// '::'[opt] 'new' new-placement[opt] new-type-id
2208 /// new-initializer[opt]
2209 /// '::'[opt] 'new' new-placement[opt] '(' type-id ')'
2210 /// new-initializer[opt]
2213 /// '(' expression-list ')'
2216 /// type-specifier-seq new-declarator[opt]
2217 /// [GNU] attributes type-specifier-seq new-declarator[opt]
2220 /// ptr-operator new-declarator[opt]
2221 /// direct-new-declarator
2223 /// new-initializer:
2224 /// '(' expression-list[opt] ')'
2225 /// [C++0x] braced-init-list
2228 Parser::ParseCXXNewExpression(bool UseGlobal, SourceLocation Start) {
2229 assert(Tok.is(tok::kw_new) && "expected 'new' token");
2230 ConsumeToken(); // Consume 'new'
2232 // A '(' now can be a new-placement or the '(' wrapping the type-id in the
2233 // second form of new-expression. It can't be a new-type-id.
2235 ExprVector PlacementArgs(Actions);
2236 SourceLocation PlacementLParen, PlacementRParen;
2238 SourceRange TypeIdParens;
2239 DeclSpec DS(AttrFactory);
2240 Declarator DeclaratorInfo(DS, Declarator::CXXNewContext);
2241 if (Tok.is(tok::l_paren)) {
2242 // If it turns out to be a placement, we change the type location.
2243 BalancedDelimiterTracker T(*this, tok::l_paren);
2245 PlacementLParen = T.getOpenLocation();
2246 if (ParseExpressionListOrTypeId(PlacementArgs, DeclaratorInfo)) {
2247 SkipUntil(tok::semi, /*StopAtSemi=*/true, /*DontConsume=*/true);
2252 PlacementRParen = T.getCloseLocation();
2253 if (PlacementRParen.isInvalid()) {
2254 SkipUntil(tok::semi, /*StopAtSemi=*/true, /*DontConsume=*/true);
2258 if (PlacementArgs.empty()) {
2259 // Reset the placement locations. There was no placement.
2260 TypeIdParens = T.getRange();
2261 PlacementLParen = PlacementRParen = SourceLocation();
2263 // We still need the type.
2264 if (Tok.is(tok::l_paren)) {
2265 BalancedDelimiterTracker T(*this, tok::l_paren);
2267 MaybeParseGNUAttributes(DeclaratorInfo);
2268 ParseSpecifierQualifierList(DS);
2269 DeclaratorInfo.SetSourceRange(DS.getSourceRange());
2270 ParseDeclarator(DeclaratorInfo);
2272 TypeIdParens = T.getRange();
2274 MaybeParseGNUAttributes(DeclaratorInfo);
2275 if (ParseCXXTypeSpecifierSeq(DS))
2276 DeclaratorInfo.setInvalidType(true);
2278 DeclaratorInfo.SetSourceRange(DS.getSourceRange());
2279 ParseDeclaratorInternal(DeclaratorInfo,
2280 &Parser::ParseDirectNewDeclarator);
2285 // A new-type-id is a simplified type-id, where essentially the
2286 // direct-declarator is replaced by a direct-new-declarator.
2287 MaybeParseGNUAttributes(DeclaratorInfo);
2288 if (ParseCXXTypeSpecifierSeq(DS))
2289 DeclaratorInfo.setInvalidType(true);
2291 DeclaratorInfo.SetSourceRange(DS.getSourceRange());
2292 ParseDeclaratorInternal(DeclaratorInfo,
2293 &Parser::ParseDirectNewDeclarator);
2296 if (DeclaratorInfo.isInvalidType()) {
2297 SkipUntil(tok::semi, /*StopAtSemi=*/true, /*DontConsume=*/true);
2301 ExprResult Initializer;
2303 if (Tok.is(tok::l_paren)) {
2304 SourceLocation ConstructorLParen, ConstructorRParen;
2305 ExprVector ConstructorArgs(Actions);
2306 BalancedDelimiterTracker T(*this, tok::l_paren);
2308 ConstructorLParen = T.getOpenLocation();
2309 if (Tok.isNot(tok::r_paren)) {
2310 CommaLocsTy CommaLocs;
2311 if (ParseExpressionList(ConstructorArgs, CommaLocs)) {
2312 SkipUntil(tok::semi, /*StopAtSemi=*/true, /*DontConsume=*/true);
2317 ConstructorRParen = T.getCloseLocation();
2318 if (ConstructorRParen.isInvalid()) {
2319 SkipUntil(tok::semi, /*StopAtSemi=*/true, /*DontConsume=*/true);
2322 Initializer = Actions.ActOnParenListExpr(ConstructorLParen,
2324 move_arg(ConstructorArgs));
2325 } else if (Tok.is(tok::l_brace) && getLangOpts().CPlusPlus0x) {
2326 Diag(Tok.getLocation(),
2327 diag::warn_cxx98_compat_generalized_initializer_lists);
2328 Initializer = ParseBraceInitializer();
2330 if (Initializer.isInvalid())
2333 return Actions.ActOnCXXNew(Start, UseGlobal, PlacementLParen,
2334 move_arg(PlacementArgs), PlacementRParen,
2335 TypeIdParens, DeclaratorInfo, Initializer.take());
2338 /// ParseDirectNewDeclarator - Parses a direct-new-declarator. Intended to be
2339 /// passed to ParseDeclaratorInternal.
2341 /// direct-new-declarator:
2342 /// '[' expression ']'
2343 /// direct-new-declarator '[' constant-expression ']'
2345 void Parser::ParseDirectNewDeclarator(Declarator &D) {
2346 // Parse the array dimensions.
2348 while (Tok.is(tok::l_square)) {
2349 // An array-size expression can't start with a lambda.
2350 if (CheckProhibitedCXX11Attribute())
2353 BalancedDelimiterTracker T(*this, tok::l_square);
2356 ExprResult Size(first ? ParseExpression()
2357 : ParseConstantExpression());
2358 if (Size.isInvalid()) {
2360 SkipUntil(tok::r_square);
2367 // Attributes here appertain to the array type. C++11 [expr.new]p5.
2368 ParsedAttributes Attrs(AttrFactory);
2369 MaybeParseCXX0XAttributes(Attrs);
2371 D.AddTypeInfo(DeclaratorChunk::getArray(0,
2372 /*static=*/false, /*star=*/false,
2374 T.getOpenLocation(),
2375 T.getCloseLocation()),
2376 Attrs, T.getCloseLocation());
2378 if (T.getCloseLocation().isInvalid())
2383 /// ParseExpressionListOrTypeId - Parse either an expression-list or a type-id.
2384 /// This ambiguity appears in the syntax of the C++ new operator.
2387 /// '::'[opt] 'new' new-placement[opt] '(' type-id ')'
2388 /// new-initializer[opt]
2391 /// '(' expression-list ')'
2393 bool Parser::ParseExpressionListOrTypeId(
2394 SmallVectorImpl<Expr*> &PlacementArgs,
2396 // The '(' was already consumed.
2397 if (isTypeIdInParens()) {
2398 ParseSpecifierQualifierList(D.getMutableDeclSpec());
2399 D.SetSourceRange(D.getDeclSpec().getSourceRange());
2401 return D.isInvalidType();
2404 // It's not a type, it has to be an expression list.
2405 // Discard the comma locations - ActOnCXXNew has enough parameters.
2406 CommaLocsTy CommaLocs;
2407 return ParseExpressionList(PlacementArgs, CommaLocs);
2410 /// ParseCXXDeleteExpression - Parse a C++ delete-expression. Delete is used
2411 /// to free memory allocated by new.
2413 /// This method is called to parse the 'delete' expression after the optional
2414 /// '::' has been already parsed. If the '::' was present, "UseGlobal" is true
2415 /// and "Start" is its location. Otherwise, "Start" is the location of the
2418 /// delete-expression:
2419 /// '::'[opt] 'delete' cast-expression
2420 /// '::'[opt] 'delete' '[' ']' cast-expression
2422 Parser::ParseCXXDeleteExpression(bool UseGlobal, SourceLocation Start) {
2423 assert(Tok.is(tok::kw_delete) && "Expected 'delete' keyword");
2424 ConsumeToken(); // Consume 'delete'
2427 bool ArrayDelete = false;
2428 if (Tok.is(tok::l_square) && NextToken().is(tok::r_square)) {
2429 // FIXME: This could be the start of a lambda-expression. We should
2430 // disambiguate this, but that will require arbitrary lookahead if
2431 // the next token is '(':
2432 // delete [](int*){ /* ... */
2434 BalancedDelimiterTracker T(*this, tok::l_square);
2438 if (T.getCloseLocation().isInvalid())
2442 ExprResult Operand(ParseCastExpression(false));
2443 if (Operand.isInvalid())
2444 return move(Operand);
2446 return Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete, Operand.take());
2449 static UnaryTypeTrait UnaryTypeTraitFromTokKind(tok::TokenKind kind) {
2451 default: llvm_unreachable("Not a known unary type trait.");
2452 case tok::kw___has_nothrow_assign: return UTT_HasNothrowAssign;
2453 case tok::kw___has_nothrow_constructor: return UTT_HasNothrowConstructor;
2454 case tok::kw___has_nothrow_copy: return UTT_HasNothrowCopy;
2455 case tok::kw___has_trivial_assign: return UTT_HasTrivialAssign;
2456 case tok::kw___has_trivial_constructor:
2457 return UTT_HasTrivialDefaultConstructor;
2458 case tok::kw___has_trivial_copy: return UTT_HasTrivialCopy;
2459 case tok::kw___has_trivial_destructor: return UTT_HasTrivialDestructor;
2460 case tok::kw___has_virtual_destructor: return UTT_HasVirtualDestructor;
2461 case tok::kw___is_abstract: return UTT_IsAbstract;
2462 case tok::kw___is_arithmetic: return UTT_IsArithmetic;
2463 case tok::kw___is_array: return UTT_IsArray;
2464 case tok::kw___is_class: return UTT_IsClass;
2465 case tok::kw___is_complete_type: return UTT_IsCompleteType;
2466 case tok::kw___is_compound: return UTT_IsCompound;
2467 case tok::kw___is_const: return UTT_IsConst;
2468 case tok::kw___is_empty: return UTT_IsEmpty;
2469 case tok::kw___is_enum: return UTT_IsEnum;
2470 case tok::kw___is_final: return UTT_IsFinal;
2471 case tok::kw___is_floating_point: return UTT_IsFloatingPoint;
2472 case tok::kw___is_function: return UTT_IsFunction;
2473 case tok::kw___is_fundamental: return UTT_IsFundamental;
2474 case tok::kw___is_integral: return UTT_IsIntegral;
2475 case tok::kw___is_lvalue_reference: return UTT_IsLvalueReference;
2476 case tok::kw___is_member_function_pointer: return UTT_IsMemberFunctionPointer;
2477 case tok::kw___is_member_object_pointer: return UTT_IsMemberObjectPointer;
2478 case tok::kw___is_member_pointer: return UTT_IsMemberPointer;
2479 case tok::kw___is_object: return UTT_IsObject;
2480 case tok::kw___is_literal: return UTT_IsLiteral;
2481 case tok::kw___is_literal_type: return UTT_IsLiteral;
2482 case tok::kw___is_pod: return UTT_IsPOD;
2483 case tok::kw___is_pointer: return UTT_IsPointer;
2484 case tok::kw___is_polymorphic: return UTT_IsPolymorphic;
2485 case tok::kw___is_reference: return UTT_IsReference;
2486 case tok::kw___is_rvalue_reference: return UTT_IsRvalueReference;
2487 case tok::kw___is_scalar: return UTT_IsScalar;
2488 case tok::kw___is_signed: return UTT_IsSigned;
2489 case tok::kw___is_standard_layout: return UTT_IsStandardLayout;
2490 case tok::kw___is_trivial: return UTT_IsTrivial;
2491 case tok::kw___is_trivially_copyable: return UTT_IsTriviallyCopyable;
2492 case tok::kw___is_union: return UTT_IsUnion;
2493 case tok::kw___is_unsigned: return UTT_IsUnsigned;
2494 case tok::kw___is_void: return UTT_IsVoid;
2495 case tok::kw___is_volatile: return UTT_IsVolatile;
2499 static BinaryTypeTrait BinaryTypeTraitFromTokKind(tok::TokenKind kind) {
2501 default: llvm_unreachable("Not a known binary type trait");
2502 case tok::kw___is_base_of: return BTT_IsBaseOf;
2503 case tok::kw___is_convertible: return BTT_IsConvertible;
2504 case tok::kw___is_same: return BTT_IsSame;
2505 case tok::kw___builtin_types_compatible_p: return BTT_TypeCompatible;
2506 case tok::kw___is_convertible_to: return BTT_IsConvertibleTo;
2507 case tok::kw___is_trivially_assignable: return BTT_IsTriviallyAssignable;
2511 static TypeTrait TypeTraitFromTokKind(tok::TokenKind kind) {
2513 default: llvm_unreachable("Not a known type trait");
2514 case tok::kw___is_trivially_constructible:
2515 return TT_IsTriviallyConstructible;
2519 static ArrayTypeTrait ArrayTypeTraitFromTokKind(tok::TokenKind kind) {
2521 default: llvm_unreachable("Not a known binary type trait");
2522 case tok::kw___array_rank: return ATT_ArrayRank;
2523 case tok::kw___array_extent: return ATT_ArrayExtent;
2527 static ExpressionTrait ExpressionTraitFromTokKind(tok::TokenKind kind) {
2529 default: llvm_unreachable("Not a known unary expression trait.");
2530 case tok::kw___is_lvalue_expr: return ET_IsLValueExpr;
2531 case tok::kw___is_rvalue_expr: return ET_IsRValueExpr;
2535 /// ParseUnaryTypeTrait - Parse the built-in unary type-trait
2536 /// pseudo-functions that allow implementation of the TR1/C++0x type traits
2539 /// primary-expression:
2540 /// [GNU] unary-type-trait '(' type-id ')'
2542 ExprResult Parser::ParseUnaryTypeTrait() {
2543 UnaryTypeTrait UTT = UnaryTypeTraitFromTokKind(Tok.getKind());
2544 SourceLocation Loc = ConsumeToken();
2546 BalancedDelimiterTracker T(*this, tok::l_paren);
2547 if (T.expectAndConsume(diag::err_expected_lparen))
2550 // FIXME: Error reporting absolutely sucks! If the this fails to parse a type
2551 // there will be cryptic errors about mismatched parentheses and missing
2553 TypeResult Ty = ParseTypeName();
2560 return Actions.ActOnUnaryTypeTrait(UTT, Loc, Ty.get(), T.getCloseLocation());
2563 /// ParseBinaryTypeTrait - Parse the built-in binary type-trait
2564 /// pseudo-functions that allow implementation of the TR1/C++0x type traits
2567 /// primary-expression:
2568 /// [GNU] binary-type-trait '(' type-id ',' type-id ')'
2570 ExprResult Parser::ParseBinaryTypeTrait() {
2571 BinaryTypeTrait BTT = BinaryTypeTraitFromTokKind(Tok.getKind());
2572 SourceLocation Loc = ConsumeToken();
2574 BalancedDelimiterTracker T(*this, tok::l_paren);
2575 if (T.expectAndConsume(diag::err_expected_lparen))
2578 TypeResult LhsTy = ParseTypeName();
2579 if (LhsTy.isInvalid()) {
2580 SkipUntil(tok::r_paren);
2584 if (ExpectAndConsume(tok::comma, diag::err_expected_comma)) {
2585 SkipUntil(tok::r_paren);
2589 TypeResult RhsTy = ParseTypeName();
2590 if (RhsTy.isInvalid()) {
2591 SkipUntil(tok::r_paren);
2597 return Actions.ActOnBinaryTypeTrait(BTT, Loc, LhsTy.get(), RhsTy.get(),
2598 T.getCloseLocation());
2601 /// \brief Parse the built-in type-trait pseudo-functions that allow
2602 /// implementation of the TR1/C++11 type traits templates.
2604 /// primary-expression:
2605 /// type-trait '(' type-id-seq ')'
2608 /// type-id ...[opt] type-id-seq[opt]
2610 ExprResult Parser::ParseTypeTrait() {
2611 TypeTrait Kind = TypeTraitFromTokKind(Tok.getKind());
2612 SourceLocation Loc = ConsumeToken();
2614 BalancedDelimiterTracker Parens(*this, tok::l_paren);
2615 if (Parens.expectAndConsume(diag::err_expected_lparen))
2618 llvm::SmallVector<ParsedType, 2> Args;
2620 // Parse the next type.
2621 TypeResult Ty = ParseTypeName();
2622 if (Ty.isInvalid()) {
2627 // Parse the ellipsis, if present.
2628 if (Tok.is(tok::ellipsis)) {
2629 Ty = Actions.ActOnPackExpansion(Ty.get(), ConsumeToken());
2630 if (Ty.isInvalid()) {
2636 // Add this type to the list of arguments.
2637 Args.push_back(Ty.get());
2639 if (Tok.is(tok::comma)) {
2647 if (Parens.consumeClose())
2650 return Actions.ActOnTypeTrait(Kind, Loc, Args, Parens.getCloseLocation());
2653 /// ParseArrayTypeTrait - Parse the built-in array type-trait
2654 /// pseudo-functions.
2656 /// primary-expression:
2657 /// [Embarcadero] '__array_rank' '(' type-id ')'
2658 /// [Embarcadero] '__array_extent' '(' type-id ',' expression ')'
2660 ExprResult Parser::ParseArrayTypeTrait() {
2661 ArrayTypeTrait ATT = ArrayTypeTraitFromTokKind(Tok.getKind());
2662 SourceLocation Loc = ConsumeToken();
2664 BalancedDelimiterTracker T(*this, tok::l_paren);
2665 if (T.expectAndConsume(diag::err_expected_lparen))
2668 TypeResult Ty = ParseTypeName();
2669 if (Ty.isInvalid()) {
2670 SkipUntil(tok::comma);
2671 SkipUntil(tok::r_paren);
2676 case ATT_ArrayRank: {
2678 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.get(), NULL,
2679 T.getCloseLocation());
2681 case ATT_ArrayExtent: {
2682 if (ExpectAndConsume(tok::comma, diag::err_expected_comma)) {
2683 SkipUntil(tok::r_paren);
2687 ExprResult DimExpr = ParseExpression();
2690 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.get(), DimExpr.get(),
2691 T.getCloseLocation());
2694 llvm_unreachable("Invalid ArrayTypeTrait!");
2697 /// ParseExpressionTrait - Parse built-in expression-trait
2698 /// pseudo-functions like __is_lvalue_expr( xxx ).
2700 /// primary-expression:
2701 /// [Embarcadero] expression-trait '(' expression ')'
2703 ExprResult Parser::ParseExpressionTrait() {
2704 ExpressionTrait ET = ExpressionTraitFromTokKind(Tok.getKind());
2705 SourceLocation Loc = ConsumeToken();
2707 BalancedDelimiterTracker T(*this, tok::l_paren);
2708 if (T.expectAndConsume(diag::err_expected_lparen))
2711 ExprResult Expr = ParseExpression();
2715 return Actions.ActOnExpressionTrait(ET, Loc, Expr.get(),
2716 T.getCloseLocation());
2720 /// ParseCXXAmbiguousParenExpression - We have parsed the left paren of a
2721 /// parenthesized ambiguous type-id. This uses tentative parsing to disambiguate
2722 /// based on the context past the parens.
2724 Parser::ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType,
2726 BalancedDelimiterTracker &Tracker) {
2727 assert(getLangOpts().CPlusPlus && "Should only be called for C++!");
2728 assert(ExprType == CastExpr && "Compound literals are not ambiguous!");
2729 assert(isTypeIdInParens() && "Not a type-id!");
2731 ExprResult Result(true);
2732 CastTy = ParsedType();
2734 // We need to disambiguate a very ugly part of the C++ syntax:
2736 // (T())x; - type-id
2737 // (T())*x; - type-id
2738 // (T())/x; - expression
2739 // (T()); - expression
2741 // The bad news is that we cannot use the specialized tentative parser, since
2742 // it can only verify that the thing inside the parens can be parsed as
2743 // type-id, it is not useful for determining the context past the parens.
2745 // The good news is that the parser can disambiguate this part without
2746 // making any unnecessary Action calls.
2748 // It uses a scheme similar to parsing inline methods. The parenthesized
2749 // tokens are cached, the context that follows is determined (possibly by
2750 // parsing a cast-expression), and then we re-introduce the cached tokens
2751 // into the token stream and parse them appropriately.
2753 ParenParseOption ParseAs;
2756 // Store the tokens of the parentheses. We will parse them after we determine
2757 // the context that follows them.
2758 if (!ConsumeAndStoreUntil(tok::r_paren, Toks)) {
2759 // We didn't find the ')' we expected.
2760 Tracker.consumeClose();
2764 if (Tok.is(tok::l_brace)) {
2765 ParseAs = CompoundLiteral;
2768 // FIXME: Special-case ++ and --: "(S())++;" is not a cast-expression
2769 if (Tok.is(tok::l_paren) && NextToken().is(tok::r_paren)) {
2772 // Try parsing the cast-expression that may follow.
2773 // If it is not a cast-expression, NotCastExpr will be true and no token
2774 // will be consumed.
2775 Result = ParseCastExpression(false/*isUnaryExpression*/,
2776 false/*isAddressofOperand*/,
2778 // type-id has priority.
2782 // If we parsed a cast-expression, it's really a type-id, otherwise it's
2784 ParseAs = NotCastExpr ? SimpleExpr : CastExpr;
2787 // The current token should go after the cached tokens.
2788 Toks.push_back(Tok);
2789 // Re-enter the stored parenthesized tokens into the token stream, so we may
2791 PP.EnterTokenStream(Toks.data(), Toks.size(),
2792 true/*DisableMacroExpansion*/, false/*OwnsTokens*/);
2793 // Drop the current token and bring the first cached one. It's the same token
2794 // as when we entered this function.
2797 if (ParseAs >= CompoundLiteral) {
2798 // Parse the type declarator.
2799 DeclSpec DS(AttrFactory);
2800 ParseSpecifierQualifierList(DS);
2801 Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
2802 ParseDeclarator(DeclaratorInfo);
2805 Tracker.consumeClose();
2807 if (ParseAs == CompoundLiteral) {
2808 ExprType = CompoundLiteral;
2809 TypeResult Ty = ParseTypeName();
2810 return ParseCompoundLiteralExpression(Ty.get(),
2811 Tracker.getOpenLocation(),
2812 Tracker.getCloseLocation());
2815 // We parsed '(' type-id ')' and the thing after it wasn't a '{'.
2816 assert(ParseAs == CastExpr);
2818 if (DeclaratorInfo.isInvalidType())
2821 // Result is what ParseCastExpression returned earlier.
2822 if (!Result.isInvalid())
2823 Result = Actions.ActOnCastExpr(getCurScope(), Tracker.getOpenLocation(),
2824 DeclaratorInfo, CastTy,
2825 Tracker.getCloseLocation(), Result.take());
2826 return move(Result);
2829 // Not a compound literal, and not followed by a cast-expression.
2830 assert(ParseAs == SimpleExpr);
2832 ExprType = SimpleExpr;
2833 Result = ParseExpression();
2834 if (!Result.isInvalid() && Tok.is(tok::r_paren))
2835 Result = Actions.ActOnParenExpr(Tracker.getOpenLocation(),
2836 Tok.getLocation(), Result.take());
2839 if (Result.isInvalid()) {
2840 SkipUntil(tok::r_paren);
2844 Tracker.consumeClose();
2845 return move(Result);