diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-12-20 18:11:52 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-12-20 18:11:52 +0000 |
commit | 2ccd89cff3f1c18b48f649240302446a7dae28b9 (patch) | |
tree | 47e2010c301d5bfe4e20a9cfacfd21c0f04de401 /lib/Sema/SemaDecl.cpp | |
parent | e7aa27a826f0b353713df6bfa0715818db8cde74 (diff) |
When performing name lookup for a redeclaration, ignore module
visibility restrictions. This ensures that all declarations of the
same entity end up in the same redeclaration chain, even if some of
those declarations aren't visible. While this may seem unfortunate to
some---why can't two C modules have different functions named
'f'?---it's an acknowedgment that a module does not introduce a new
"namespace" of names.
As part of this, stop merging the 'module-private' bit from previous
declarations to later declarations, because we want each declaration
in a module to stand on its own because this can effect, for example,
submodule visibility.
Note that this notion of names that are invisible to normal name
lookup but are available for redeclaration lookups is how we should
implement friend declarations and extern declarations within local
function scopes. I'm not tackling that problem now.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146980 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 42 |
1 files changed, 1 insertions, 41 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index c31850313a..ebcdcf58d0 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1456,12 +1456,6 @@ void Sema::MergeTypedefNameDecl(TypedefNameDecl *New, LookupResult &OldDecls) { if (TypedefNameDecl *Typedef = dyn_cast<TypedefNameDecl>(Old)) New->setPreviousDeclaration(Typedef); - // __module_private__ is propagated to later declarations. - if (Old->isModulePrivate()) - New->setModulePrivate(); - else if (New->isModulePrivate()) - diagnoseModulePrivateRedeclaration(New, Old); - if (getLangOptions().MicrosoftExt) return; @@ -2047,12 +2041,6 @@ bool Sema::MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old) { if (Old->isPure()) New->setPure(); - // __module_private__ is propagated to later declarations. - if (Old->isModulePrivate()) - New->setModulePrivate(); - else if (New->isModulePrivate()) - diagnoseModulePrivateRedeclaration(New, Old); - // Merge attributes from the parameters. These can mismatch with K&R // declarations. if (New->getNumParams() == Old->getNumParams()) @@ -2237,12 +2225,6 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) { return New->setInvalidDecl(); } - // __module_private__ is propagated to later declarations. - if (Old->isModulePrivate()) - New->setModulePrivate(); - else if (New->isModulePrivate()) - diagnoseModulePrivateRedeclaration(New, Old); - // Variables with external linkage are analyzed in FinalizeDeclaratorGroup. // FIXME: The test for external storage here seems wrong? We still @@ -5627,9 +5609,6 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, assert(OldTemplateDecl->isMemberSpecialization()); } - if (OldTemplateDecl->isModulePrivate()) - NewTemplateDecl->setModulePrivate(); - } else { if (isa<CXXMethodDecl>(NewFD)) // Set access for out-of-line definitions NewFD->setAccess(OldDecl->getAccess()); @@ -8212,19 +8191,14 @@ CreateNewDecl: AddMsStructLayoutForRecord(RD); } - if (PrevDecl && PrevDecl->isModulePrivate()) - New->setModulePrivate(); - else if (ModulePrivateLoc.isValid()) { + if (ModulePrivateLoc.isValid()) { if (isExplicitSpecialization) Diag(New->getLocation(), diag::err_module_private_specialization) << 2 << FixItHint::CreateRemoval(ModulePrivateLoc); - else if (PrevDecl && !PrevDecl->isModulePrivate()) - diagnoseModulePrivateRedeclaration(New, PrevDecl, ModulePrivateLoc); // __module_private__ does not apply to local classes. However, we only // diagnose this as an error when the declaration specifiers are // freestanding. Here, we just ignore the __module_private__. - // foobar else if (!SearchDC->isFunctionOrMethod()) New->setModulePrivate(); } @@ -9969,20 +9943,6 @@ DeclResult Sema::ActOnModuleImport(SourceLocation ImportLoc, ModuleIdPath Path) return Import; } -void -Sema::diagnoseModulePrivateRedeclaration(NamedDecl *New, NamedDecl *Old, - SourceLocation ModulePrivateKeyword) { - assert(!Old->isModulePrivate() && "Old is module-private!"); - - Diag(New->getLocation(), diag::err_module_private_follows_public) - << New->getDeclName() << SourceRange(ModulePrivateKeyword); - Diag(Old->getLocation(), diag::note_previous_declaration) - << Old->getDeclName(); - - // Drop the __module_private__ from the new declaration, since it's invalid. - New->setModulePrivate(false); -} - void Sema::ActOnPragmaWeakID(IdentifierInfo* Name, SourceLocation PragmaLoc, SourceLocation NameLoc) { |