Skip to content

Commit

Permalink
Change return value of trivial visibility check.
Browse files Browse the repository at this point in the history
Previous, if no Decl's were checked, visibility was set to false.  Switch it
so that in cases of no Decl's, return true.  These are the Decl's after being
filtered.  Also remove an unreachable return statement since it is directly
after another return statement.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@334160 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Weverything committed Jun 7, 2018
1 parent 57ebd13 commit 9185154
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/Sema/SemaLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,8 @@ template<typename Filter>
static bool hasVisibleDeclarationImpl(Sema &S, const NamedDecl *D,
llvm::SmallVectorImpl<Module *> *Modules,
Filter F) {
bool HasFilteredRedecls = false;

for (auto *Redecl : D->redecls()) {
auto *R = cast<NamedDecl>(Redecl);
if (!F(R))
Expand All @@ -1460,14 +1462,20 @@ static bool hasVisibleDeclarationImpl(Sema &S, const NamedDecl *D,
if (S.isVisible(R))
return true;

HasFilteredRedecls = true;

if (Modules) {
Modules->push_back(R->getOwningModule());
const auto &Merged = S.Context.getModulesWithMergedDefinition(R);
Modules->insert(Modules->end(), Merged.begin(), Merged.end());
}
}

return false;
// Only return false if there is at least one redecl that is not filtered out.
if (HasFilteredRedecls)
return false;

return true;
}

bool Sema::hasVisibleExplicitSpecialization(
Expand Down Expand Up @@ -1497,8 +1505,6 @@ bool Sema::hasVisibleMemberSpecialization(
// class definition?
return D->getLexicalDeclContext()->isFileContext();
});

return false;
}

/// Determine whether a declaration is visible to name lookup.
Expand Down
15 changes: 15 additions & 0 deletions test/Modules/local-visibility.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: %clang_cc1 -fsyntax-only -fmodules %s -verify
// RUN: %clang_cc1 -fsyntax-only %s -verify

// expected-no-diagnostics
template <typename Var>
struct S {
template <unsigned N>
struct Inner { };

template <>
struct Inner<0> { };
};

S<int>::Inner<1> I1;
S<int>::Inner<0> I0;

0 comments on commit 9185154

Please sign in to comment.