@@ -2021,7 +2021,7 @@ bool Sema::isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New) {
2021
2021
Diag(New->getLocation(), diag::err_redefinition_variably_modified_typedef)
2022
2022
<< Kind << NewType;
2023
2023
if (Old->getLocation().isValid())
2024
- notePreviousDefinition(Old->getLocation() , New->getLocation());
2024
+ notePreviousDefinition(Old, New->getLocation());
2025
2025
New->setInvalidDecl();
2026
2026
return true;
2027
2027
}
@@ -2034,7 +2034,7 @@ bool Sema::isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New) {
2034
2034
Diag(New->getLocation(), diag::err_redefinition_different_typedef)
2035
2035
<< Kind << NewType << OldType;
2036
2036
if (Old->getLocation().isValid())
2037
- notePreviousDefinition(Old->getLocation() , New->getLocation());
2037
+ notePreviousDefinition(Old, New->getLocation());
2038
2038
New->setInvalidDecl();
2039
2039
return true;
2040
2040
}
@@ -2101,7 +2101,7 @@ void Sema::MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New,
2101
2101
2102
2102
NamedDecl *OldD = OldDecls.getRepresentativeDecl();
2103
2103
if (OldD->getLocation().isValid())
2104
- notePreviousDefinition(OldD->getLocation() , New->getLocation());
2104
+ notePreviousDefinition(OldD, New->getLocation());
2105
2105
2106
2106
return New->setInvalidDecl();
2107
2107
}
@@ -2193,7 +2193,7 @@ void Sema::MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New,
2193
2193
2194
2194
Diag(New->getLocation(), diag::err_redefinition)
2195
2195
<< New->getDeclName();
2196
- notePreviousDefinition(Old->getLocation() , New->getLocation());
2196
+ notePreviousDefinition(Old, New->getLocation());
2197
2197
return New->setInvalidDecl();
2198
2198
}
2199
2199
@@ -2214,7 +2214,7 @@ void Sema::MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New,
2214
2214
2215
2215
Diag(New->getLocation(), diag::ext_redefinition_of_typedef)
2216
2216
<< New->getDeclName();
2217
- notePreviousDefinition(Old->getLocation() , New->getLocation());
2217
+ notePreviousDefinition(Old, New->getLocation());
2218
2218
}
2219
2219
2220
2220
/// DeclhasAttr - returns true if decl Declaration already has the target
@@ -2448,7 +2448,7 @@ static bool mergeDeclAttribute(Sema &S, NamedDecl *D,
2448
2448
return false;
2449
2449
}
2450
2450
2451
- static const Decl *getDefinition(const Decl *D) {
2451
+ static const NamedDecl *getDefinition(const Decl *D) {
2452
2452
if (const TagDecl *TD = dyn_cast<TagDecl>(D))
2453
2453
return TD->getDefinition();
2454
2454
if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
@@ -2475,7 +2475,7 @@ static void checkNewAttributesAfterDef(Sema &S, Decl *New, const Decl *Old) {
2475
2475
if (!New->hasAttrs())
2476
2476
return;
2477
2477
2478
- const Decl *Def = getDefinition(Old);
2478
+ const NamedDecl *Def = getDefinition(Old);
2479
2479
if (!Def || Def == New)
2480
2480
return;
2481
2481
@@ -2502,7 +2502,7 @@ static void checkNewAttributesAfterDef(Sema &S, Decl *New, const Decl *Old) {
2502
2502
: diag::err_redefinition;
2503
2503
S.Diag(VD->getLocation(), Diag) << VD->getDeclName();
2504
2504
if (Diag == diag::err_redefinition)
2505
- S.notePreviousDefinition(Def->getLocation() , VD->getLocation());
2505
+ S.notePreviousDefinition(Def, VD->getLocation());
2506
2506
else
2507
2507
S.Diag(Def->getLocation(), diag::note_previous_definition);
2508
2508
VD->setInvalidDecl();
@@ -2891,7 +2891,7 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD,
2891
2891
} else {
2892
2892
Diag(New->getLocation(), diag::err_redefinition_different_kind)
2893
2893
<< New->getDeclName();
2894
- notePreviousDefinition(OldD->getLocation() , New->getLocation());
2894
+ notePreviousDefinition(OldD, New->getLocation());
2895
2895
return true;
2896
2896
}
2897
2897
}
@@ -2928,7 +2928,7 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD,
2928
2928
!Old->hasAttr<InternalLinkageAttr>()) {
2929
2929
Diag(New->getLocation(), diag::err_internal_linkage_redeclaration)
2930
2930
<< New->getDeclName();
2931
- notePreviousDefinition(Old->getLocation() , New->getLocation());
2931
+ notePreviousDefinition(Old, New->getLocation());
2932
2932
New->dropAttr<InternalLinkageAttr>();
2933
2933
}
2934
2934
@@ -3657,7 +3657,7 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) {
3657
3657
if (!Old) {
3658
3658
Diag(New->getLocation(), diag::err_redefinition_different_kind)
3659
3659
<< New->getDeclName();
3660
- notePreviousDefinition(Previous.getRepresentativeDecl()->getLocation() ,
3660
+ notePreviousDefinition(Previous.getRepresentativeDecl(),
3661
3661
New->getLocation());
3662
3662
return New->setInvalidDecl();
3663
3663
}
@@ -3687,7 +3687,7 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) {
3687
3687
Old->getStorageClass() == SC_None &&
3688
3688
!Old->hasAttr<WeakImportAttr>()) {
3689
3689
Diag(New->getLocation(), diag::warn_weak_import) << New->getDeclName();
3690
- notePreviousDefinition(Old->getLocation() , New->getLocation());
3690
+ notePreviousDefinition(Old, New->getLocation());
3691
3691
// Remove weak_import attribute on new declaration.
3692
3692
New->dropAttr<WeakImportAttr>();
3693
3693
}
@@ -3696,7 +3696,7 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) {
3696
3696
!Old->hasAttr<InternalLinkageAttr>()) {
3697
3697
Diag(New->getLocation(), diag::err_internal_linkage_redeclaration)
3698
3698
<< New->getDeclName();
3699
- notePreviousDefinition(Old->getLocation() , New->getLocation());
3699
+ notePreviousDefinition(Old, New->getLocation());
3700
3700
New->dropAttr<InternalLinkageAttr>();
3701
3701
}
3702
3702
@@ -3853,29 +3853,22 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) {
3853
3853
New->setImplicitlyInline();
3854
3854
}
3855
3855
3856
- void Sema::notePreviousDefinition(SourceLocation Old, SourceLocation New) {
3856
+ void Sema::notePreviousDefinition(const NamedDecl * Old, SourceLocation New) {
3857
3857
SourceManager &SrcMgr = getSourceManager();
3858
3858
auto FNewDecLoc = SrcMgr.getDecomposedLoc(New);
3859
- auto FOldDecLoc = SrcMgr.getDecomposedLoc(Old);
3859
+ auto FOldDecLoc = SrcMgr.getDecomposedLoc(Old->getLocation() );
3860
3860
auto *FNew = SrcMgr.getFileEntryForID(FNewDecLoc.first);
3861
3861
auto *FOld = SrcMgr.getFileEntryForID(FOldDecLoc.first);
3862
3862
auto &HSI = PP.getHeaderSearchInfo();
3863
- StringRef HdrFilename = SrcMgr.getFilename(SrcMgr.getSpellingLoc(Old));
3863
+ StringRef HdrFilename =
3864
+ SrcMgr.getFilename(SrcMgr.getSpellingLoc(Old->getLocation()));
3864
3865
3865
- auto noteFromModuleOrInclude = [&](SourceLocation &Loc,
3866
- SourceLocation &IncLoc) -> bool {
3867
- Module *Mod = nullptr;
3866
+ auto noteFromModuleOrInclude = [&](Module *Mod,
3867
+ SourceLocation IncLoc) -> bool {
3868
3868
// Redefinition errors with modules are common with non modular mapped
3869
3869
// headers, example: a non-modular header H in module A that also gets
3870
3870
// included directly in a TU. Pointing twice to the same header/definition
3871
3871
// is confusing, try to get better diagnostics when modules is on.
3872
- if (getLangOpts().Modules) {
3873
- auto ModLoc = SrcMgr.getModuleImportLoc(Old);
3874
- if (!ModLoc.first.isInvalid())
3875
- Mod = HSI.getModuleMap().inferModuleFromLocation(
3876
- FullSourceLoc(Loc, SrcMgr));
3877
- }
3878
-
3879
3872
if (IncLoc.isValid()) {
3880
3873
if (Mod) {
3881
3874
Diag(IncLoc, diag::note_redefinition_modules_same_file)
@@ -3899,19 +3892,19 @@ void Sema::notePreviousDefinition(SourceLocation Old, SourceLocation New) {
3899
3892
if (FNew == FOld && FNewDecLoc.second == FOldDecLoc.second) {
3900
3893
SourceLocation OldIncLoc = SrcMgr.getIncludeLoc(FOldDecLoc.first);
3901
3894
SourceLocation NewIncLoc = SrcMgr.getIncludeLoc(FNewDecLoc.first);
3902
- EmittedDiag = noteFromModuleOrInclude(Old, OldIncLoc);
3903
- EmittedDiag |= noteFromModuleOrInclude(New , NewIncLoc);
3895
+ EmittedDiag = noteFromModuleOrInclude(Old->getOwningModule() , OldIncLoc);
3896
+ EmittedDiag |= noteFromModuleOrInclude(getCurrentModule() , NewIncLoc);
3904
3897
3905
3898
// If the header has no guards, emit a note suggesting one.
3906
3899
if (FOld && !HSI.isFileMultipleIncludeGuarded(FOld))
3907
- Diag(Old, diag::note_use_ifdef_guards);
3900
+ Diag(Old->getLocation() , diag::note_use_ifdef_guards);
3908
3901
3909
3902
if (EmittedDiag)
3910
3903
return;
3911
3904
}
3912
3905
3913
3906
// Redefinition coming from different files or couldn't do better above.
3914
- Diag(Old, diag::note_previous_definition);
3907
+ Diag(Old->getLocation() , diag::note_previous_definition);
3915
3908
}
3916
3909
3917
3910
/// We've just determined that \p Old and \p New both appear to be definitions
@@ -3934,7 +3927,7 @@ bool Sema::checkVarDeclRedefinition(VarDecl *Old, VarDecl *New) {
3934
3927
return false;
3935
3928
} else {
3936
3929
Diag(New->getLocation(), diag::err_redefinition) << New;
3937
- notePreviousDefinition(Old->getLocation() , New->getLocation());
3930
+ notePreviousDefinition(Old, New->getLocation());
3938
3931
New->setInvalidDecl();
3939
3932
return true;
3940
3933
}
@@ -13503,9 +13496,7 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
13503
13496
} else if (TUK == TUK_Reference &&
13504
13497
(PrevTagDecl->getFriendObjectKind() ==
13505
13498
Decl::FOK_Undeclared ||
13506
- PP.getModuleContainingLocation(
13507
- PrevDecl->getLocation()) !=
13508
- PP.getModuleContainingLocation(KWLoc)) &&
13499
+ PrevDecl->getOwningModule() != getCurrentModule()) &&
13509
13500
SS.isEmpty()) {
13510
13501
// This declaration is a reference to an existing entity, but
13511
13502
// has different visibility from that entity: it either makes
@@ -13561,7 +13552,7 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
13561
13552
Diag(NameLoc, diag::warn_redefinition_in_param_list) << Name;
13562
13553
else
13563
13554
Diag(NameLoc, diag::err_redefinition) << Name;
13564
- notePreviousDefinition(Def->getLocation() ,
13555
+ notePreviousDefinition(Def,
13565
13556
NameLoc.isValid() ? NameLoc : KWLoc);
13566
13557
// If this is a redefinition, recover by making this
13567
13558
// struct be anonymous, which will make any later
@@ -13652,7 +13643,7 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
13652
13643
// The tag name clashes with something else in the target scope,
13653
13644
// issue an error and recover by making this tag be anonymous.
13654
13645
Diag(NameLoc, diag::err_redefinition_different_kind) << Name;
13655
- notePreviousDefinition(PrevDecl->getLocation() , NameLoc);
13646
+ notePreviousDefinition(PrevDecl, NameLoc);
13656
13647
Name = nullptr;
13657
13648
Invalid = true;
13658
13649
}
@@ -15356,7 +15347,7 @@ Decl *Sema::ActOnEnumConstant(Scope *S, Decl *theEnumDecl, Decl *lastEnumConst,
15356
15347
Diag(IdLoc, diag::err_redefinition_of_enumerator) << Id;
15357
15348
else
15358
15349
Diag(IdLoc, diag::err_redefinition) << Id;
15359
- notePreviousDefinition(PrevDecl->getLocation() , IdLoc);
15350
+ notePreviousDefinition(PrevDecl, IdLoc);
15360
15351
return nullptr;
15361
15352
}
15362
15353
}
0 commit comments