diff options
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 85 |
1 files changed, 16 insertions, 69 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 85582d302de..78ceeedc3ac 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -1448,46 +1448,6 @@ void Sema::FilterLookupForScope(LookupResult &R, DeclContext *Ctx, Scope *S, F.done(); } -/// We've determined that \p New is a redeclaration of \p Old. Check that they -/// have compatible owning modules. -bool Sema::CheckRedeclarationModuleOwnership(NamedDecl *New, NamedDecl *Old) { - // FIXME: The Modules TS is not clear about how friend declarations are - // to be treated. It's not meaningful to have different owning modules for - // linkage in redeclarations of the same entity, so for now allow the - // redeclaration and change the owning modules to match. - if (New->getFriendObjectKind() && - Old->getOwningModuleForLinkage() != New->getOwningModuleForLinkage()) { - New->setLocalOwningModule(Old->getOwningModule()); - makeMergedDefinitionVisible(New); - return false; - } - - Module *NewM = New->getOwningModule(); - Module *OldM = Old->getOwningModule(); - if (NewM == OldM) - return false; - - // FIXME: Check proclaimed-ownership-declarations here too. - bool NewIsModuleInterface = NewM && NewM->Kind == Module::ModuleInterfaceUnit; - bool OldIsModuleInterface = OldM && OldM->Kind == Module::ModuleInterfaceUnit; - if (NewIsModuleInterface || OldIsModuleInterface) { - // C++ Modules TS [basic.def.odr] 6.2/6.7 [sic]: - // if a declaration of D [...] appears in the purview of a module, all - // other such declarations shall appear in the purview of the same module - Diag(New->getLocation(), diag::err_mismatched_owning_module) - << New - << NewIsModuleInterface - << (NewIsModuleInterface ? NewM->getFullModuleName() : "") - << OldIsModuleInterface - << (OldIsModuleInterface ? OldM->getFullModuleName() : ""); - Diag(Old->getLocation(), diag::note_previous_declaration); - New->setInvalidDecl(); - return true; - } - - return false; -} - static bool isUsingDecl(NamedDecl *D) { return isa<UsingShadowDecl>(D) || isa<UnresolvedUsingTypenameDecl>(D) || @@ -3002,9 +2962,6 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD, New->dropAttr<InternalLinkageAttr>(); } - if (CheckRedeclarationModuleOwnership(New, Old)) - return true; - if (!getLangOpts().CPlusPlus) { bool OldOvl = Old->hasAttr<OverloadableAttr>(); if (OldOvl != New->hasAttr<OverloadableAttr>() && !Old->isImplicit()) { @@ -3874,9 +3831,6 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) { return New->setInvalidDecl(); } - if (CheckRedeclarationModuleOwnership(New, Old)) - return; - // Variables with external linkage are analyzed in FinalizeDeclaratorGroup. // FIXME: The test for external storage here seems wrong? We still @@ -4428,7 +4382,7 @@ static bool CheckAnonMemberRedeclaration(Sema &SemaRef, SourceLocation NameLoc, bool IsUnion) { LookupResult R(SemaRef, Name, NameLoc, Sema::LookupMemberName, - Sema::ForVisibleRedeclaration); + Sema::ForRedeclaration); if (!SemaRef.LookupName(R, S)) return false; // Pick a representative declaration. @@ -5367,7 +5321,7 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator &D, D.setInvalidType(); LookupResult Previous(*this, NameInfo, LookupOrdinaryName, - forRedeclarationInCurContext()); + ForRedeclaration); // See if this is a redefinition of a variable in the same scope. if (!D.getCXXScopeSpec().isSet()) { @@ -5393,10 +5347,8 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator &D, D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_static) CreateBuiltins = true; - if (IsLinkageLookup) { + if (IsLinkageLookup) Previous.clear(LookupRedeclarationWithLinkage); - Previous.setRedeclarationKind(ForExternalRedeclaration); - } LookupName(Previous, S, CreateBuiltins); } else { // Something like "int foo::x;" @@ -7144,7 +7096,7 @@ void Sema::CheckShadow(Scope *S, VarDecl *D) { return; LookupResult R(*this, D->getDeclName(), D->getLocation(), - Sema::LookupOrdinaryName, Sema::ForVisibleRedeclaration); + Sema::LookupOrdinaryName, Sema::ForRedeclaration); LookupName(R, S); if (NamedDecl *ShadowedDecl = getShadowedDeclaration(D, R)) CheckShadow(D, ShadowedDecl, R); @@ -7720,7 +7672,7 @@ static NamedDecl *DiagnoseInvalidRedeclaration( LookupResult Prev(SemaRef, Name, NewFD->getLocation(), IsLocalFriend ? Sema::LookupLocalFriendName : Sema::LookupOrdinaryName, - Sema::ForVisibleRedeclaration); + Sema::ForRedeclaration); NewFD->setInvalidDecl(); if (IsLocalFriend) @@ -11756,7 +11708,7 @@ Decl *Sema::ActOnParamDeclarator(Scope *S, Declarator &D) { // Check for redeclaration of parameters, e.g. int foo(int x, int x); if (II) { LookupResult R(*this, II, D.getIdentifierLoc(), LookupOrdinaryName, - ForVisibleRedeclaration); + ForRedeclaration); LookupName(R, S); if (R.isSingleResult()) { NamedDecl *PrevDecl = R.getFoundDecl(); @@ -13316,7 +13268,7 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, bool isStdBadAlloc = false; bool isStdAlignValT = false; - RedeclarationKind Redecl = forRedeclarationInCurContext(); + RedeclarationKind Redecl = ForRedeclaration; if (TUK == TUK_Friend || TUK == TUK_Reference) Redecl = NotForRedeclaration; @@ -13594,10 +13546,10 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, // type declared by an elaborated-type-specifier. In C that is not correct // and we should instead merge compatible types found by lookup. if (getLangOpts().CPlusPlus) { - Previous.setRedeclarationKind(forRedeclarationInCurContext()); + Previous.setRedeclarationKind(ForRedeclaration); LookupQualifiedName(Previous, SearchDC); } else { - Previous.setRedeclarationKind(forRedeclarationInCurContext()); + Previous.setRedeclarationKind(ForRedeclaration); LookupName(Previous, S); } } @@ -14095,9 +14047,6 @@ CreateNewDecl: if (!Invalid && SearchDC->isRecord()) SetMemberAccessSpecifier(New, PrevDecl, AS); - if (PrevDecl) - CheckRedeclarationModuleOwnership(New, PrevDecl); - if (TUK == TUK_Definition) New->startDefinition(); @@ -14451,8 +14400,7 @@ FieldDecl *Sema::HandleField(Scope *S, RecordDecl *Record, // Check to see if this name was declared as a member previously NamedDecl *PrevDecl = nullptr; - LookupResult Previous(*this, II, Loc, LookupMemberName, - ForVisibleRedeclaration); + LookupResult Previous(*this, II, Loc, LookupMemberName, ForRedeclaration); LookupName(Previous, S); switch (Previous.getResultKind()) { case LookupResult::Found: @@ -14840,7 +14788,7 @@ Decl *Sema::ActOnIvar(Scope *S, if (II) { NamedDecl *PrevDecl = LookupSingleName(S, II, Loc, LookupMemberName, - ForVisibleRedeclaration); + ForRedeclaration); if (PrevDecl && isDeclInScope(PrevDecl, EnclosingContext, S) && !isa<TagDecl>(PrevDecl)) { Diag(Loc, diag::err_duplicate_member) << II; @@ -15561,7 +15509,7 @@ Sema::SkipBodyInfo Sema::shouldSkipAnonEnumBody(Scope *S, IdentifierInfo *II, // determine if we should merge the definition with an existing one and // skip the body. NamedDecl *PrevDecl = LookupSingleName(S, II, IILoc, LookupOrdinaryName, - forRedeclarationInCurContext()); + ForRedeclaration); auto *PrevECD = dyn_cast_or_null<EnumConstantDecl>(PrevDecl); if (!PrevECD) return SkipBodyInfo(); @@ -15592,7 +15540,7 @@ Decl *Sema::ActOnEnumConstant(Scope *S, Decl *theEnumDecl, Decl *lastEnumConst, // Verify that there isn't already something declared with this name in this // scope. NamedDecl *PrevDecl = LookupSingleName(S, Id, IdLoc, LookupOrdinaryName, - ForVisibleRedeclaration); + ForRedeclaration); if (PrevDecl && PrevDecl->isTemplateParameter()) { // Maybe we will complain about the shadowed template parameter. DiagnoseTemplateParameterShadow(IdLoc, PrevDecl); @@ -15619,7 +15567,8 @@ Decl *Sema::ActOnEnumConstant(Scope *S, Decl *theEnumDecl, Decl *lastEnumConst, // enum constant will 'hide' the tag. assert((getLangOpts().CPlusPlus || !isa<TagDecl>(PrevDecl)) && "Received TagDecl when not in C++!"); - if (!isa<TagDecl>(PrevDecl) && isDeclInScope(PrevDecl, CurContext, S)) { + if (!isa<TagDecl>(PrevDecl) && isDeclInScope(PrevDecl, CurContext, S) && + shouldLinkPossiblyHiddenDecl(PrevDecl, New)) { if (isa<EnumConstantDecl>(PrevDecl)) Diag(IdLoc, diag::err_redefinition_of_enumerator) << Id; else @@ -16201,8 +16150,7 @@ Sema::DeclGroupPtrTy Sema::ActOnModuleDecl(SourceLocation StartLoc, else if (const auto *FE = M->getASTFile()) Diag(M->DefinitionLoc, diag::note_prev_module_definition_from_ast_file) << FE->getName(); - Mod = M; - break; + return nullptr; } // Create a Module for the module that we're defining. @@ -16221,7 +16169,6 @@ Sema::DeclGroupPtrTy Sema::ActOnModuleDecl(SourceLocation StartLoc, PP.getIdentifierInfo(ModuleName), Path[0].second); Mod = getModuleLoader().loadModule(ModuleLoc, Path, Module::AllVisible, /*IsIncludeDirective=*/false); - // FIXME: Produce an error in this case. if (!Mod) return nullptr; break; |