diff options
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 196 |
1 files changed, 85 insertions, 111 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index ca851bd53e0..906fd89ff24 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -1739,8 +1739,8 @@ static void GenerateFixForUnusedDecl(const NamedDecl *D, ASTContext &Ctx, tok::colon, Ctx.getSourceManager(), Ctx.getLangOpts(), true); if (AfterColon.isInvalid()) return; - Hint = FixItHint::CreateRemoval(CharSourceRange:: - getCharRange(D->getLocStart(), AfterColon)); + Hint = FixItHint::CreateRemoval( + CharSourceRange::getCharRange(D->getBeginLoc(), AfterColon)); } } @@ -4351,8 +4351,8 @@ Sema::ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, Record = UT->getDecl(); if (Record && getLangOpts().MicrosoftExt) { - Diag(DS.getLocStart(), diag::ext_ms_anonymous_record) - << Record->isUnion() << DS.getSourceRange(); + Diag(DS.getBeginLoc(), diag::ext_ms_anonymous_record) + << Record->isUnion() << DS.getSourceRange(); return BuildMicrosoftCAnonymousStruct(S, DS, Record); } @@ -4375,8 +4375,8 @@ Sema::ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, if (!DS.isMissingDeclaratorOk()) { // Customize diagnostic for a typedef missing a name. if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) - Diag(DS.getLocStart(), diag::ext_typedef_without_a_name) - << DS.getSourceRange(); + Diag(DS.getBeginLoc(), diag::ext_typedef_without_a_name) + << DS.getSourceRange(); else DeclaresAnything = false; } @@ -4400,7 +4400,7 @@ Sema::ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, if (!DeclaresAnything) { // In C, we allow this as a (popular) extension / bug. Don't bother // producing further diagnostics for redundant qualifiers after this. - Diag(DS.getLocStart(), diag::ext_no_declarators) << DS.getSourceRange(); + Diag(DS.getBeginLoc(), diag::ext_no_declarators) << DS.getSourceRange(); return TagD; } @@ -4810,14 +4810,11 @@ Decl *Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, // Create a declaration for this anonymous struct/union. NamedDecl *Anon = nullptr; if (RecordDecl *OwningClass = dyn_cast<RecordDecl>(Owner)) { - Anon = FieldDecl::Create(Context, OwningClass, - DS.getLocStart(), - Record->getLocation(), - /*IdentifierInfo=*/nullptr, - Context.getTypeDeclType(Record), - TInfo, - /*BitWidth=*/nullptr, /*Mutable=*/false, - /*InitStyle=*/ICIS_NoInit); + Anon = FieldDecl::Create( + Context, OwningClass, DS.getBeginLoc(), Record->getLocation(), + /*IdentifierInfo=*/nullptr, Context.getTypeDeclType(Record), TInfo, + /*BitWidth=*/nullptr, /*Mutable=*/false, + /*InitStyle=*/ICIS_NoInit); Anon->setAccess(AS); if (getLangOpts().CPlusPlus) FieldCollector->Add(cast<FieldDecl>(Anon)); @@ -4832,11 +4829,9 @@ Decl *Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, SC = SC_None; } - Anon = VarDecl::Create(Context, Owner, - DS.getLocStart(), + Anon = VarDecl::Create(Context, Owner, DS.getBeginLoc(), Record->getLocation(), /*IdentifierInfo=*/nullptr, - Context.getTypeDeclType(Record), - TInfo, SC); + Context.getTypeDeclType(Record), TInfo, SC); // Default-initialize the implicit variable. This initialization will be // trivial in almost all cases, except if a union member has an in-class @@ -4908,15 +4903,11 @@ Decl *Sema::BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS, QualType RecTy = Context.getTypeDeclType(Record); // Create a declaration for this anonymous struct. - NamedDecl *Anon = FieldDecl::Create(Context, - ParentDecl, - DS.getLocStart(), - DS.getLocStart(), - /*IdentifierInfo=*/nullptr, - RecTy, - TInfo, - /*BitWidth=*/nullptr, /*Mutable=*/false, - /*InitStyle=*/ICIS_NoInit); + NamedDecl *Anon = + FieldDecl::Create(Context, ParentDecl, DS.getBeginLoc(), DS.getBeginLoc(), + /*IdentifierInfo=*/nullptr, RecTy, TInfo, + /*BitWidth=*/nullptr, /*Mutable=*/false, + /*InitStyle=*/ICIS_NoInit); Anon->setImplicit(); // Add the anonymous struct object to the current context. @@ -5344,9 +5335,8 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator &D, return ActOnDecompositionDeclarator(S, D, TemplateParamLists); } else if (!Name) { if (!D.isInvalidType()) // Reject this if we think it is valid. - Diag(D.getDeclSpec().getLocStart(), - diag::err_declarator_need_ident) - << D.getDeclSpec().getSourceRange() << D.getSourceRange(); + Diag(D.getDeclSpec().getBeginLoc(), diag::err_declarator_need_ident) + << D.getDeclSpec().getSourceRange() << D.getSourceRange(); return nullptr; } else if (DiagnoseUnexpandedParameterPack(NameInfo, UPPC_DeclarationType)) return nullptr; @@ -6378,7 +6368,7 @@ NamedDecl *Sema::ActOnVariableDeclarator( // address space qualifiers. if (R->isEventT()) { if (R.getAddressSpace() != LangAS::opencl_private) { - Diag(D.getLocStart(), diag::err_event_t_addr_space_qual); + Diag(D.getBeginLoc(), diag::err_event_t_addr_space_qual); D.setInvalidType(); } } @@ -6452,9 +6442,8 @@ NamedDecl *Sema::ActOnVariableDeclarator( VarTemplateDecl *NewTemplate = nullptr; TemplateParameterList *TemplateParams = nullptr; if (!getLangOpts().CPlusPlus) { - NewVD = VarDecl::Create(Context, DC, D.getLocStart(), - D.getIdentifierLoc(), II, - R, TInfo, SC); + NewVD = VarDecl::Create(Context, DC, D.getBeginLoc(), D.getIdentifierLoc(), + II, R, TInfo, SC); if (R->getContainedDeducedType()) ParsingInitForAutoVars.insert(NewVD); @@ -6516,7 +6505,7 @@ NamedDecl *Sema::ActOnVariableDeclarator( // Match up the template parameter lists with the scope specifier, then // determine whether we have a template or a template specialization. TemplateParams = MatchTemplateParametersToScopeSpecifier( - D.getDeclSpec().getLocStart(), D.getIdentifierLoc(), + D.getDeclSpec().getBeginLoc(), D.getIdentifierLoc(), D.getCXXScopeSpec(), D.getName().getKind() == UnqualifiedIdKind::IK_TemplateId ? D.getName().TemplateId @@ -6575,11 +6564,11 @@ NamedDecl *Sema::ActOnVariableDeclarator( NewVD = cast<VarDecl>(Res.get()); AddToScope = false; } else if (D.isDecompositionDeclarator()) { - NewVD = DecompositionDecl::Create(Context, DC, D.getLocStart(), + NewVD = DecompositionDecl::Create(Context, DC, D.getBeginLoc(), D.getIdentifierLoc(), R, TInfo, SC, Bindings); } else - NewVD = VarDecl::Create(Context, DC, D.getLocStart(), + NewVD = VarDecl::Create(Context, DC, D.getBeginLoc(), D.getIdentifierLoc(), II, R, TInfo, SC); // If this is supposed to be a variable template, create it as such. @@ -6796,7 +6785,7 @@ NamedDecl *Sema::ActOnVariableDeclarator( } if (!R->isIntegralType(Context) && !R->isPointerType()) { - Diag(D.getLocStart(), diag::err_asm_bad_register_type); + Diag(D.getBeginLoc(), diag::err_asm_bad_register_type); NewVD->setInvalidDecl(true); } } @@ -6926,12 +6915,12 @@ NamedDecl *Sema::ActOnVariableDeclarator( // C++ [basic.start.main]p3 // A program that declares a variable main at global scope is ill-formed. if (getLangOpts().CPlusPlus) - Diag(D.getLocStart(), diag::err_main_global_variable); + Diag(D.getBeginLoc(), diag::err_main_global_variable); // In C, and external-linkage variable named main results in undefined // behavior. else if (NewVD->hasExternalFormalLinkage()) - Diag(D.getLocStart(), diag::warn_main_redefined); + Diag(D.getBeginLoc(), diag::warn_main_redefined); } if (D.isRedeclaration() && !Previous.empty()) { @@ -7933,10 +7922,8 @@ static FunctionDecl* CreateNewFunctionDecl(Sema &SemaRef, Declarator &D, (D.isFunctionDeclarator() && D.getFunctionTypeInfo().hasPrototype) || (!R->getAsAdjusted<FunctionType>() && R->isFunctionProtoType()); - NewFD = FunctionDecl::Create(SemaRef.Context, DC, - D.getLocStart(), NameInfo, R, - TInfo, SC, isInline, - HasPrototype, false); + NewFD = FunctionDecl::Create(SemaRef.Context, DC, D.getBeginLoc(), NameInfo, + R, TInfo, SC, isInline, HasPrototype, false); if (D.isInvalidType()) NewFD->setInvalidDecl(); @@ -7961,22 +7948,20 @@ static FunctionDecl* CreateNewFunctionDecl(Sema &SemaRef, Declarator &D, "Constructors can only be declared in a member context"); R = SemaRef.CheckConstructorDeclarator(D, R, SC); - return CXXConstructorDecl::Create(SemaRef.Context, cast<CXXRecordDecl>(DC), - D.getLocStart(), NameInfo, - R, TInfo, isExplicit, isInline, - /*isImplicitlyDeclared=*/false, - isConstexpr); + return CXXConstructorDecl::Create( + SemaRef.Context, cast<CXXRecordDecl>(DC), D.getBeginLoc(), NameInfo, R, + TInfo, isExplicit, isInline, + /*isImplicitlyDeclared=*/false, isConstexpr); } else if (Name.getNameKind() == DeclarationName::CXXDestructorName) { // This is a C++ destructor declaration. if (DC->isRecord()) { R = SemaRef.CheckDestructorDeclarator(D, R, SC); CXXRecordDecl *Record = cast<CXXRecordDecl>(DC); - CXXDestructorDecl *NewDD = CXXDestructorDecl::Create( - SemaRef.Context, Record, - D.getLocStart(), - NameInfo, R, TInfo, isInline, - /*isImplicitlyDeclared=*/false); + CXXDestructorDecl *NewDD = + CXXDestructorDecl::Create(SemaRef.Context, Record, D.getBeginLoc(), + NameInfo, R, TInfo, isInline, + /*isImplicitlyDeclared=*/false); // If the class is complete, then we now create the implicit exception // specification. If the class is incomplete or dependent, we can't do @@ -7996,10 +7981,9 @@ static FunctionDecl* CreateNewFunctionDecl(Sema &SemaRef, Declarator &D, // Create a FunctionDecl to satisfy the function definition parsing // code path. - return FunctionDecl::Create(SemaRef.Context, DC, - D.getLocStart(), - D.getIdentifierLoc(), Name, R, TInfo, - SC, isInline, + return FunctionDecl::Create(SemaRef.Context, DC, D.getBeginLoc(), + D.getIdentifierLoc(), Name, R, TInfo, SC, + isInline, /*hasPrototype=*/true, isConstexpr); } @@ -8012,15 +7996,14 @@ static FunctionDecl* CreateNewFunctionDecl(Sema &SemaRef, Declarator &D, SemaRef.CheckConversionDeclarator(D, R, SC); IsVirtualOkay = true; - return CXXConversionDecl::Create(SemaRef.Context, cast<CXXRecordDecl>(DC), - D.getLocStart(), NameInfo, - R, TInfo, isInline, isExplicit, - isConstexpr, SourceLocation()); + return CXXConversionDecl::Create( + SemaRef.Context, cast<CXXRecordDecl>(DC), D.getBeginLoc(), NameInfo, R, + TInfo, isInline, isExplicit, isConstexpr, SourceLocation()); } else if (Name.getNameKind() == DeclarationName::CXXDeductionGuideName) { SemaRef.CheckDeductionGuideDeclarator(D, R, SC); - return CXXDeductionGuideDecl::Create(SemaRef.Context, DC, D.getLocStart(), + return CXXDeductionGuideDecl::Create(SemaRef.Context, DC, D.getBeginLoc(), isExplicit, NameInfo, R, TInfo, D.getLocEnd()); } else if (DC->isRecord()) { @@ -8037,11 +8020,9 @@ static FunctionDecl* CreateNewFunctionDecl(Sema &SemaRef, Declarator &D, } // This is a C++ method declaration. - CXXMethodDecl *Ret = CXXMethodDecl::Create(SemaRef.Context, - cast<CXXRecordDecl>(DC), - D.getLocStart(), NameInfo, R, - TInfo, SC, isInline, - isConstexpr, SourceLocation()); + CXXMethodDecl *Ret = CXXMethodDecl::Create( + SemaRef.Context, cast<CXXRecordDecl>(DC), D.getBeginLoc(), NameInfo, R, + TInfo, SC, isInline, isConstexpr, SourceLocation()); IsVirtualOkay = !Ret->isStatic(); return Ret; } else { @@ -8053,10 +8034,9 @@ static FunctionDecl* CreateNewFunctionDecl(Sema &SemaRef, Declarator &D, // Determine whether the function was written with a // prototype. This true when: // - we're in C++ (where every function has a prototype), - return FunctionDecl::Create(SemaRef.Context, DC, - D.getLocStart(), - NameInfo, R, TInfo, SC, isInline, - true/*HasPrototype*/, isConstexpr); + return FunctionDecl::Create(SemaRef.Context, DC, D.getBeginLoc(), NameInfo, + R, TInfo, SC, isInline, true /*HasPrototype*/, + isConstexpr); } } @@ -8421,7 +8401,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, bool Invalid = false; if (TemplateParameterList *TemplateParams = MatchTemplateParametersToScopeSpecifier( - D.getDeclSpec().getLocStart(), D.getIdentifierLoc(), + D.getDeclSpec().getBeginLoc(), D.getIdentifierLoc(), D.getCXXScopeSpec(), D.getName().getKind() == UnqualifiedIdKind::IK_TemplateId ? D.getName().TemplateId @@ -8491,8 +8471,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, << FixItHint::CreateInsertion(InsertLoc, "<>"); } } - } - else { + } else { // All template param lists were matched against the scope specifier: // this is NOT (an explicit specialization of) a template. if (TemplateParamLists.size() > 0) @@ -10111,7 +10090,7 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, // A deduction guide is not on the list of entities that can be // explicitly specialized. if (Guide->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) - Diag(Guide->getLocStart(), diag::err_deduction_guide_specialized) + Diag(Guide->getBeginLoc(), diag::err_deduction_guide_specialized) << /*explicit specialization*/ 1; } @@ -10714,11 +10693,10 @@ namespace { return; } - S.DiagRuntimeBehavior(DRE->getLocStart(), DRE, + S.DiagRuntimeBehavior(DRE->getBeginLoc(), DRE, S.PDiag(diag) - << DRE->getDecl() - << OrigDecl->getLocation() - << DRE->getSourceRange()); + << DRE->getDecl() << OrigDecl->getLocation() + << DRE->getSourceRange()); } }; @@ -10817,7 +10795,7 @@ QualType Sema::deduceVarTypeFromInitializer(VarDecl *VDecl, if (DeduceInits.empty()) { // It isn't possible to write this directly, but it is possible to // end up in this situation with "auto x(some_pack...);" - Diag(Init->getLocStart(), IsInitCapture + Diag(Init->getBeginLoc(), IsInitCapture ? diag::err_init_capture_no_expression : diag::err_auto_var_init_no_expression) << VN << Type << Range; @@ -10825,7 +10803,7 @@ QualType Sema::deduceVarTypeFromInitializer(VarDecl *VDecl, } if (DeduceInits.size() > 1) { - Diag(DeduceInits[1]->getLocStart(), + Diag(DeduceInits[1]->getBeginLoc(), IsInitCapture ? diag::err_init_capture_multiple_expressions : diag::err_auto_var_init_multiple_expressions) << VN << Type << Range; @@ -10834,7 +10812,7 @@ QualType Sema::deduceVarTypeFromInitializer(VarDecl *VDecl, Expr *DeduceInit = DeduceInits[0]; if (DirectInit && isa<InitListExpr>(DeduceInit)) { - Diag(Init->getLocStart(), IsInitCapture + Diag(Init->getBeginLoc(), IsInitCapture ? diag::err_init_capture_paren_braces : diag::err_auto_var_init_paren_braces) << isa<InitListExpr>(Init) << VN << Type << Range; @@ -11139,7 +11117,7 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) { if ((VDecl->getType().getObjCLifetime() == Qualifiers::OCL_Strong || VDecl->getType().isNonWeakInMRRWithObjCWeak(Context)) && !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, - Init->getLocStart())) + Init->getBeginLoc())) FSI->markSafeWeakUse(Init); } @@ -11271,9 +11249,9 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) { Diag(VDecl->getLocation(), diag::ext_in_class_initializer_float_type_cxx11) << DclT << Init->getSourceRange(); - Diag(VDecl->getLocStart(), + Diag(VDecl->getBeginLoc(), diag::note_in_class_initializer_float_type_cxx11) - << FixItHint::CreateInsertion(VDecl->getLocStart(), "constexpr "); + << FixItHint::CreateInsertion(VDecl->getBeginLoc(), "constexpr "); } else { Diag(VDecl->getLocation(), diag::ext_in_class_initializer_float_type) << DclT << Init->getSourceRange(); @@ -11288,8 +11266,8 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) { // Suggest adding 'constexpr' in C++11 for literal types. } else if (getLangOpts().CPlusPlus11 && DclT->isLiteralType(Context)) { Diag(VDecl->getLocation(), diag::err_in_class_initializer_literal_type) - << DclT << Init->getSourceRange() - << FixItHint::CreateInsertion(VDecl->getLocStart(), "constexpr "); + << DclT << Init->getSourceRange() + << FixItHint::CreateInsertion(VDecl->getBeginLoc(), "constexpr "); VDecl->setConstexpr(true); } else { @@ -12370,11 +12348,9 @@ Decl *Sema::ActOnParamDeclarator(Scope *S, Declarator &D) { // Temporarily put parameter variables in the translation unit, not // the enclosing context. This prevents them from accidentally // looking like class members in C++. - ParmVarDecl *New = CheckParameter(Context.getTranslationUnitDecl(), - D.getLocStart(), - D.getIdentifierLoc(), II, - parmDeclType, TInfo, - SC); + ParmVarDecl *New = + CheckParameter(Context.getTranslationUnitDecl(), D.getBeginLoc(), + D.getIdentifierLoc(), II, parmDeclType, TInfo, SC); if (D.isInvalidType()) New->setInvalidDecl(); @@ -13111,7 +13087,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body, if (FD->isMultiVersion() && FD->hasAttr<CPUDispatchAttr>() && Body) if (const auto *CmpndBody = dyn_cast<CompoundStmt>(Body)) if (!CmpndBody->body_empty()) - Diag(CmpndBody->body_front()->getLocStart(), + Diag(CmpndBody->body_front()->getBeginLoc(), diag::warn_dispatch_body_ignored); if (auto *MD = dyn_cast<CXXMethodDecl>(FD)) { @@ -13262,7 +13238,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body, if (RegisterVariables) continue; if (!isa<AsmStmt>(S) && !isa<NullStmt>(S)) { - Diag(S->getLocStart(), diag::err_non_asm_stmt_in_naked_function); + Diag(S->getBeginLoc(), diag::err_non_asm_stmt_in_naked_function); Diag(FD->getAttr<NakedAttr>()->getLocation(), diag::note_attribute); FD->setInvalidDecl(); break; @@ -13568,11 +13544,9 @@ TypedefDecl *Sema::ParseTypedefDecl(Scope *S, Declarator &D, QualType T, } // Scope manipulation handled by caller. - TypedefDecl *NewTD = TypedefDecl::Create(Context, CurContext, - D.getLocStart(), - D.getIdentifierLoc(), - D.getIdentifier(), - TInfo); + TypedefDecl *NewTD = + TypedefDecl::Create(Context, CurContext, D.getBeginLoc(), + D.getIdentifierLoc(), D.getIdentifier(), TInfo); // Bail out immediately if we have an invalid declaration. if (D.isInvalidType()) { @@ -14863,12 +14837,11 @@ void Sema::ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagD, // class itself; this is known as the injected-class-name. For // purposes of access checking, the injected-class-name is treated // as if it were a public member name. - CXXRecordDecl *InjectedClassName - = CXXRecordDecl::Create(Context, Record->getTagKind(), CurContext, - Record->getLocStart(), Record->getLocation(), - Record->getIdentifier(), - /*PrevDecl=*/nullptr, - /*DelayTypeCreation=*/true); + CXXRecordDecl *InjectedClassName = CXXRecordDecl::Create( + Context, Record->getTagKind(), CurContext, Record->getBeginLoc(), + Record->getLocation(), Record->getIdentifier(), + /*PrevDecl=*/nullptr, + /*DelayTypeCreation=*/true); Context.getTypeDeclType(InjectedClassName, Record); InjectedClassName->setImplicit(); InjectedClassName->setAccess(AS_public); @@ -15135,7 +15108,7 @@ FieldDecl *Sema::HandleField(Scope *S, RecordDecl *Record, bool Mutable = (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_mutable); - SourceLocation TSSL = D.getLocStart(); + SourceLocation TSSL = D.getBeginLoc(); FieldDecl *NewFD = CheckFieldDecl(II, T, TInfo, Record, Loc, Mutable, BitWidth, InitStyle, TSSL, AS, PrevDecl, &D); @@ -16771,7 +16744,7 @@ static void checkModuleImportContext(Sema &S, Module *M, switch (LSD->getLanguage()) { case LinkageSpecDecl::lang_c: if (ExternCLoc.isInvalid()) - ExternCLoc = LSD->getLocStart(); + ExternCLoc = LSD->getBeginLoc(); break; case LinkageSpecDecl::lang_cxx: break; @@ -16787,8 +16760,9 @@ static void checkModuleImportContext(Sema &S, Module *M, ? diag::ext_module_import_not_at_top_level_noop : diag::err_module_import_not_at_top_level_fatal) << M->getFullModuleName() << DC; - S.Diag(cast<Decl>(DC)->getLocStart(), - diag::note_module_import_not_at_top_level) << DC; + S.Diag(cast<Decl>(DC)->getBeginLoc(), + diag::note_module_import_not_at_top_level) + << DC; } else if (!M->IsExternC && ExternCLoc.isValid()) { S.Diag(ImportLoc, diag::ext_module_import_in_extern_c) << M->getFullModuleName(); |