diff options
Diffstat (limited to 'gnu/llvm/tools/clang/lib/Parse/ParseExprCXX.cpp')
| -rw-r--r-- | gnu/llvm/tools/clang/lib/Parse/ParseExprCXX.cpp | 121 |
1 files changed, 69 insertions, 52 deletions
diff --git a/gnu/llvm/tools/clang/lib/Parse/ParseExprCXX.cpp b/gnu/llvm/tools/clang/lib/Parse/ParseExprCXX.cpp index dcafbadae5c..554ab24b02e 100644 --- a/gnu/llvm/tools/clang/lib/Parse/ParseExprCXX.cpp +++ b/gnu/llvm/tools/clang/lib/Parse/ParseExprCXX.cpp @@ -249,7 +249,7 @@ bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS, if (Tok.is(tok::code_completion)) { // Code completion for a nested-name-specifier, where the code - // code completion token follows the '::'. + // completion token follows the '::'. Actions.CodeCompleteQualifiedId(getCurScope(), SS, EnteringContext); // Include code completion token into the range of the scope otherwise // when we try to annotate the scope tokens the dangling code completion @@ -292,8 +292,8 @@ bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS, break; } - if (TemplateName.getKind() != UnqualifiedId::IK_OperatorFunctionId && - TemplateName.getKind() != UnqualifiedId::IK_LiteralOperatorId) { + if (TemplateName.getKind() != UnqualifiedIdKind::IK_OperatorFunctionId && + TemplateName.getKind() != UnqualifiedIdKind::IK_LiteralOperatorId) { Diag(TemplateName.getSourceRange().getBegin(), diag::err_id_after_template_in_nested_name_spec) << TemplateName.getSourceRange(); @@ -966,6 +966,8 @@ Optional<unsigned> Parser::ParseLambdaIntroducer(LambdaIntroducer &Intro, // that would be an error. ParsedType InitCaptureType; + if (!Init.isInvalid()) + Init = Actions.CorrectDelayedTyposInExpr(Init.get()); if (Init.isUsable()) { // Get the pointer and store it in an lvalue, so we can use it as an // out argument. @@ -989,27 +991,34 @@ Optional<unsigned> Parser::ParseLambdaIntroducer(LambdaIntroducer &Intro, /// /// Returns true if it hit something unexpected. bool Parser::TryParseLambdaIntroducer(LambdaIntroducer &Intro) { - TentativeParsingAction PA(*this); + { + bool SkippedInits = false; + TentativeParsingAction PA1(*this); - bool SkippedInits = false; - Optional<unsigned> DiagID(ParseLambdaIntroducer(Intro, &SkippedInits)); + if (ParseLambdaIntroducer(Intro, &SkippedInits)) { + PA1.Revert(); + return true; + } - if (DiagID) { - PA.Revert(); - return true; + if (!SkippedInits) { + PA1.Commit(); + return false; + } + + PA1.Revert(); } - if (SkippedInits) { - // Parse it again, but this time parse the init-captures too. - PA.Revert(); - Intro = LambdaIntroducer(); - DiagID = ParseLambdaIntroducer(Intro); - assert(!DiagID && "parsing lambda-introducer failed on reparse"); + // Try to parse it again, but this time parse the init-captures too. + Intro = LambdaIntroducer(); + TentativeParsingAction PA2(*this); + + if (!ParseLambdaIntroducer(Intro)) { + PA2.Commit(); return false; } - PA.Commit(); - return false; + PA2.Revert(); + return true; } static void @@ -1053,8 +1062,8 @@ static void addConstexprToLambdaDeclSpecifier(Parser &P, SourceLocation ConstexprLoc, DeclSpec &DS) { if (ConstexprLoc.isValid()) { - P.Diag(ConstexprLoc, !P.getLangOpts().CPlusPlus1z - ? diag::ext_constexpr_on_lambda_cxx1z + P.Diag(ConstexprLoc, !P.getLangOpts().CPlusPlus17 + ? diag::ext_constexpr_on_lambda_cxx17 : diag::warn_cxx14_compat_constexpr_on_lambda); const char *PrevSpec = nullptr; unsigned DiagID = 0; @@ -1081,7 +1090,7 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer( // Parse lambda-declarator[opt]. DeclSpec DS(AttrFactory); - Declarator D(DS, Declarator::LambdaExprContext); + Declarator D(DS, DeclaratorContext::LambdaExprContext); TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth); Actions.PushLambdaScope(); @@ -1281,7 +1290,8 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer( // FIXME: Rename BlockScope -> ClosureScope if we decide to continue using // it. - unsigned ScopeFlags = Scope::BlockScope | Scope::FnScope | Scope::DeclScope; + unsigned ScopeFlags = Scope::BlockScope | Scope::FnScope | Scope::DeclScope | + Scope::CompoundStmtScope; ParseScope BodyScope(this, ScopeFlags); Actions.ActOnStartOfLambdaDefinition(Intro, D, getCurScope()); @@ -1343,7 +1353,7 @@ ExprResult Parser::ParseCXXCasts() { ParseSpecifierQualifierList(DS); // Parse the abstract-declarator, if present. - Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); + Declarator DeclaratorInfo(DS, DeclaratorContext::TypeNameContext); ParseDeclarator(DeclaratorInfo); SourceLocation RAngleBracketLoc = Tok.getLocation(); @@ -1351,7 +1361,6 @@ ExprResult Parser::ParseCXXCasts() { if (ExpectAndConsume(tok::greater)) return ExprError(Diag(LAngleBracketLoc, diag::note_matching) << tok::less); - SourceLocation LParenLoc, RParenLoc; BalancedDelimiterTracker T(*this, tok::l_paren); if (T.expectAndConsume(diag::err_expected_lparen_after, CastName)) @@ -1651,7 +1660,7 @@ ExprResult Parser::ParseCXXThis() { /// In C++1z onwards, the type specifier can also be a template-name. ExprResult Parser::ParseCXXTypeConstructExpression(const DeclSpec &DS) { - Declarator DeclaratorInfo(DS, Declarator::FunctionalCastContext); + Declarator DeclaratorInfo(DS, DeclaratorContext::FunctionalCastContext); ParsedType TypeRep = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo).get(); assert((Tok.is(tok::l_paren) || @@ -1706,6 +1715,8 @@ Parser::ParseCXXTypeConstructExpression(const DeclSpec &DS) { /// type-specifier-seq declarator '=' assignment-expression /// [C++11] type-specifier-seq declarator '=' initializer-clause /// [C++11] type-specifier-seq declarator braced-init-list +/// [Clang] type-specifier-seq ref-qualifier[opt] '[' identifier-list ']' +/// brace-or-equal-initializer /// [GNU] type-specifier-seq declarator simple-asm-expr[opt] attributes[opt] /// '=' assignment-expression /// @@ -1751,13 +1762,14 @@ Sema::ConditionResult Parser::ParseCXXCondition(StmtResult *InitStmt, } case ConditionOrInitStatement::InitStmtDecl: { - Diag(Tok.getLocation(), getLangOpts().CPlusPlus1z + Diag(Tok.getLocation(), getLangOpts().CPlusPlus17 ? diag::warn_cxx14_compat_init_statement : diag::ext_init_statement) << (CK == Sema::ConditionKind::Switch); SourceLocation DeclStart = Tok.getLocation(), DeclEnd; - DeclGroupPtrTy DG = ParseSimpleDeclaration( - Declarator::InitStmtContext, DeclEnd, attrs, /*RequireSemi=*/true); + DeclGroupPtrTy DG = + ParseSimpleDeclaration(DeclaratorContext::InitStmtContext, DeclEnd, + attrs, /*RequireSemi=*/true); *InitStmt = Actions.ActOnDeclStmt(DG, DeclStart, DeclEnd); return ParseCXXCondition(nullptr, Loc, CK); } @@ -1770,10 +1782,10 @@ Sema::ConditionResult Parser::ParseCXXCondition(StmtResult *InitStmt, // type-specifier-seq DeclSpec DS(AttrFactory); DS.takeAttributesFrom(attrs); - ParseSpecifierQualifierList(DS, AS_none, DSC_condition); + ParseSpecifierQualifierList(DS, AS_none, DeclSpecContext::DSC_condition); // declarator - Declarator DeclaratorInfo(DS, Declarator::ConditionContext); + Declarator DeclaratorInfo(DS, DeclaratorContext::ConditionContext); ParseDeclarator(DeclaratorInfo); // simple-asm-expr[opt] @@ -1925,6 +1937,9 @@ void Parser::ParseCXXSimpleTypeSpecifier(DeclSpec &DS) { case tok::kw_double: DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec, DiagID, Policy); break; + case tok::kw__Float16: + DS.SetTypeSpecType(DeclSpec::TST_float16, Loc, PrevSpec, DiagID, Policy); + break; case tok::kw___float128: DS.SetTypeSpecType(DeclSpec::TST_float128, Loc, PrevSpec, DiagID, Policy); break; @@ -1968,7 +1983,7 @@ void Parser::ParseCXXSimpleTypeSpecifier(DeclSpec &DS) { /// type-specifier type-specifier-seq[opt] /// bool Parser::ParseCXXTypeSpecifierSeq(DeclSpec &DS) { - ParseSpecifierQualifierList(DS, AS_none, DSC_type_specifier); + ParseSpecifierQualifierList(DS, AS_none, DeclSpecContext::DSC_type_specifier); DS.Finish(Actions, Actions.getASTContext().getPrintingPolicy()); return false; } @@ -2019,9 +2034,9 @@ bool Parser::ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS, TemplateTy Template; TemplateNameKind TNK = TNK_Non_template; switch (Id.getKind()) { - case UnqualifiedId::IK_Identifier: - case UnqualifiedId::IK_OperatorFunctionId: - case UnqualifiedId::IK_LiteralOperatorId: + case UnqualifiedIdKind::IK_Identifier: + case UnqualifiedIdKind::IK_OperatorFunctionId: + case UnqualifiedIdKind::IK_LiteralOperatorId: if (AssumeTemplateId) { // We defer the injected-class-name checks until we've found whether // this template-id is used to form a nested-name-specifier or not. @@ -2044,11 +2059,11 @@ bool Parser::ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS, // parse correctly as a template, so suggest the keyword 'template' // before 'getAs' and treat this as a dependent template name. std::string Name; - if (Id.getKind() == UnqualifiedId::IK_Identifier) + if (Id.getKind() == UnqualifiedIdKind::IK_Identifier) Name = Id.Identifier->getName(); else { Name = "operator "; - if (Id.getKind() == UnqualifiedId::IK_OperatorFunctionId) + if (Id.getKind() == UnqualifiedIdKind::IK_OperatorFunctionId) Name += getOperatorSpelling(Id.OperatorFunctionId.Operator); else Name += Id.Identifier->getName(); @@ -2065,7 +2080,7 @@ bool Parser::ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS, } break; - case UnqualifiedId::IK_ConstructorName: { + case UnqualifiedIdKind::IK_ConstructorName: { UnqualifiedId TemplateName; bool MemberOfUnknownSpecialization; TemplateName.setIdentifier(Name, NameLoc); @@ -2076,7 +2091,7 @@ bool Parser::ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS, break; } - case UnqualifiedId::IK_DestructorName: { + case UnqualifiedIdKind::IK_DestructorName: { UnqualifiedId TemplateName; bool MemberOfUnknownSpecialization; TemplateName.setIdentifier(Name, NameLoc); @@ -2115,18 +2130,20 @@ bool Parser::ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS, true, LAngleLoc, TemplateArgs, RAngleLoc)) return true; - if (Id.getKind() == UnqualifiedId::IK_Identifier || - Id.getKind() == UnqualifiedId::IK_OperatorFunctionId || - Id.getKind() == UnqualifiedId::IK_LiteralOperatorId) { + if (Id.getKind() == UnqualifiedIdKind::IK_Identifier || + Id.getKind() == UnqualifiedIdKind::IK_OperatorFunctionId || + Id.getKind() == UnqualifiedIdKind::IK_LiteralOperatorId) { // Form a parsed representation of the template-id to be stored in the // UnqualifiedId. // FIXME: Store name for literal operator too. IdentifierInfo *TemplateII = - Id.getKind() == UnqualifiedId::IK_Identifier ? Id.Identifier : nullptr; - OverloadedOperatorKind OpKind = Id.getKind() == UnqualifiedId::IK_Identifier - ? OO_None - : Id.OperatorFunctionId.Operator; + Id.getKind() == UnqualifiedIdKind::IK_Identifier ? Id.Identifier + : nullptr; + OverloadedOperatorKind OpKind = + Id.getKind() == UnqualifiedIdKind::IK_Identifier + ? OO_None + : Id.OperatorFunctionId.Operator; TemplateIdAnnotation *TemplateId = TemplateIdAnnotation::Create( SS, TemplateKWLoc, Id.StartLocation, TemplateII, OpKind, Template, TNK, @@ -2148,7 +2165,7 @@ bool Parser::ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS, if (Type.isInvalid()) return true; - if (Id.getKind() == UnqualifiedId::IK_ConstructorName) + if (Id.getKind() == UnqualifiedIdKind::IK_ConstructorName) Id.setConstructorName(Type.get(), NameLoc, RAngleLoc); else Id.setDestructorName(Id.StartLocation, Type.get(), RAngleLoc); @@ -2172,7 +2189,7 @@ bool Parser::ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS, /// ! = < > += -= *= /= %= /// ^= &= |= << >> >>= <<= == != /// <= >= && || ++ -- , ->* -> -/// () [] +/// () [] <=> /// /// conversion-function-id: [C++ 12.3.2] /// operator conversion-type-id @@ -2381,7 +2398,7 @@ bool Parser::ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext, // Parse the conversion-declarator, which is merely a sequence of // ptr-operators. - Declarator D(DS, Declarator::ConversionIdContext); + Declarator D(DS, DeclaratorContext::ConversionIdContext); ParseDeclaratorInternal(D, /*DirectDeclParser=*/nullptr); // Finish up the type. @@ -2468,7 +2485,7 @@ bool Parser::ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, /*IsCtorOrDtorName=*/true, /*NonTrivialTypeSourceInfo=*/true); Result.setConstructorName(Ty, IdLoc, IdLoc); - } else if (getLangOpts().CPlusPlus1z && + } else if (getLangOpts().CPlusPlus17 && AllowDeductionGuide && SS.isEmpty() && Actions.isDeductionGuideName(getCurScope(), *Id, IdLoc, &TemplateName)) { @@ -2542,8 +2559,8 @@ bool Parser::ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, // // template-id: // operator-function-id < template-argument-list[opt] > - if ((Result.getKind() == UnqualifiedId::IK_OperatorFunctionId || - Result.getKind() == UnqualifiedId::IK_LiteralOperatorId) && + if ((Result.getKind() == UnqualifiedIdKind::IK_OperatorFunctionId || + Result.getKind() == UnqualifiedIdKind::IK_LiteralOperatorId) && (TemplateSpecified || Tok.is(tok::less))) return ParseUnqualifiedIdTemplateId(SS, TemplateKWLoc, nullptr, SourceLocation(), @@ -2682,7 +2699,7 @@ Parser::ParseCXXNewExpression(bool UseGlobal, SourceLocation Start) { SourceRange TypeIdParens; DeclSpec DS(AttrFactory); - Declarator DeclaratorInfo(DS, Declarator::CXXNewContext); + Declarator DeclaratorInfo(DS, DeclaratorContext::CXXNewContext); if (Tok.is(tok::l_paren)) { // If it turns out to be a placement, we change the type location. BalancedDelimiterTracker T(*this, tok::l_paren); @@ -3158,7 +3175,7 @@ Parser::ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType, if (ParseAs >= CompoundLiteral) { // Parse the type declarator. DeclSpec DS(AttrFactory); - Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); + Declarator DeclaratorInfo(DS, DeclaratorContext::TypeNameContext); { ColonProtectionRAIIObject InnerColonProtection(*this); ParseSpecifierQualifierList(DS); |
