[modules] A using-declaration doesn't introduce a new entity, just a new name

for an existing entity, and as such a using-declaration doesn't need to
conflict with a hidden entity (nor vice versa).

llvm-svn: 247654
This commit is contained in:
Richard Smith 2015-09-15 01:28:55 +00:00
parent ca5ab2b0d4
commit f091e129db
5 changed files with 112 additions and 3 deletions

View File

@ -237,6 +237,11 @@ public:
/// \brief Determine whether this lookup is permitted to see hidden /// \brief Determine whether this lookup is permitted to see hidden
/// declarations, such as those in modules that have not yet been imported. /// declarations, such as those in modules that have not yet been imported.
bool isHiddenDeclarationVisible(NamedDecl *ND) const { bool isHiddenDeclarationVisible(NamedDecl *ND) const {
// If a using-shadow declaration is hidden, it's never visible, not
// even to redeclaration lookup.
// FIXME: Should this apply to typedefs and namespace aliases too?
if (isa<UsingShadowDecl>(ND))
return false;
return (AllowHidden && return (AllowHidden &&
(AllowHiddenInternal || ND->isExternallyVisible())) || (AllowHiddenInternal || ND->isExternallyVisible())) ||
LookupKind == Sema::LookupTagName; LookupKind == Sema::LookupTagName;

View File

@ -7821,7 +7821,8 @@ bool Sema::CheckUsingShadowDecl(UsingDecl *Using, NamedDecl *Orig,
FoundEquivalentDecl = true; FoundEquivalentDecl = true;
} }
(isa<TagDecl>(D) ? Tag : NonTag) = D; if (isVisible(D))
(isa<TagDecl>(D) ? Tag : NonTag) = D;
} }
if (FoundEquivalentDecl) if (FoundEquivalentDecl)

View File

@ -896,6 +896,11 @@ Sema::CheckOverload(Scope *S, FunctionDecl *New, const LookupResult &Old,
OldD = cast<UsingShadowDecl>(OldD)->getTargetDecl(); OldD = cast<UsingShadowDecl>(OldD)->getTargetDecl();
} }
// A using-declaration does not conflict with another declaration
// if one of them is hidden.
if ((OldIsUsingDecl || NewIsUsingDecl) && !isVisible(*I))
continue;
// If either declaration was introduced by a using declaration, // If either declaration was introduced by a using declaration,
// we'll need to use slightly different rules for matching. // we'll need to use slightly different rules for matching.
// Essentially, these rules are the normal rules, except that // Essentially, these rules are the normal rules, except that

View File

@ -9,3 +9,29 @@ namespace UsingDecl {
using ::using_decl_type; using ::using_decl_type;
using ::using_decl_var; using ::using_decl_var;
} }
namespace X {
int conflicting_hidden_using_decl;
int conflicting_hidden_using_decl_fn();
int conflicting_hidden_using_decl_var;
struct conflicting_hidden_using_decl_struct;
int conflicting_hidden_using_decl_mixed_1;
int conflicting_hidden_using_decl_mixed_2();
struct conflicting_hidden_using_decl_mixed_3 {};
}
using X::conflicting_hidden_using_decl;
using X::conflicting_hidden_using_decl_fn;
using X::conflicting_hidden_using_decl_var;
using X::conflicting_hidden_using_decl_struct;
int conflicting_hidden_using_decl_fn_2();
int conflicting_hidden_using_decl_var_2;
struct conflicting_hidden_using_decl_struct_2 {};
using X::conflicting_hidden_using_decl_mixed_1;
using X::conflicting_hidden_using_decl_mixed_2;
using X::conflicting_hidden_using_decl_mixed_3;
int conflicting_hidden_using_decl_mixed_4;
int conflicting_hidden_using_decl_mixed_5();
struct conflicting_hidden_using_decl_mixed_6 {};

View File

@ -1,8 +1,80 @@
// RUN: rm -rf %t // RUN: rm -rf %t
// RUN: %clang_cc1 -x objective-c++ -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs %s -verify // RUN: %clang_cc1 -x objective-c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs %s -verify -DEARLY_IMPORT
// RUN: %clang_cc1 -x objective-c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs %s -verify -UEARLY_IMPORT
// RUN: %clang_cc1 -x objective-c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs %s -verify -DEARLY_IMPORT -fno-modules-hide-internal-linkage
// RUN: %clang_cc1 -x objective-c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs %s -verify -UEARLY_IMPORT -fno-modules-hide-internal-linkage
#ifdef EARLY_IMPORT
@import using_decl.a; @import using_decl.a;
#endif
namespace Y {
int conflicting_hidden_using_decl;
int conflicting_hidden_using_decl_fn_2();
int conflicting_hidden_using_decl_var_2;
struct conflicting_hidden_using_decl_struct_2;
struct conflicting_hidden_using_decl_mixed_4 {};
int conflicting_hidden_using_decl_mixed_5;
int conflicting_hidden_using_decl_mixed_6();
}
using Y::conflicting_hidden_using_decl;
int conflicting_hidden_using_decl_fn();
int conflicting_hidden_using_decl_var;
struct conflicting_hidden_using_decl_struct {};
using Y::conflicting_hidden_using_decl_fn_2;
using Y::conflicting_hidden_using_decl_var_2;
using Y::conflicting_hidden_using_decl_struct_2;
struct conflicting_hidden_using_decl_mixed_1 {};
int conflicting_hidden_using_decl_mixed_2;
int conflicting_hidden_using_decl_mixed_3();
using Y::conflicting_hidden_using_decl_mixed_4;
using Y::conflicting_hidden_using_decl_mixed_5;
using Y::conflicting_hidden_using_decl_mixed_6;
template<typename T> int use(T);
void test_conflicting() {
use(conflicting_hidden_using_decl);
use(conflicting_hidden_using_decl_fn());
use(conflicting_hidden_using_decl_var);
use(conflicting_hidden_using_decl_fn_2());
use(conflicting_hidden_using_decl_var_2);
use(conflicting_hidden_using_decl_mixed_1());
use(conflicting_hidden_using_decl_mixed_2);
use(conflicting_hidden_using_decl_mixed_3());
use(conflicting_hidden_using_decl_mixed_4());
use(conflicting_hidden_using_decl_mixed_5);
use(conflicting_hidden_using_decl_mixed_6());
}
#ifndef EARLY_IMPORT
@import using_decl.a;
#endif
// expected-no-diagnostics
UsingDecl::using_decl_type x = UsingDecl::using_decl_var; UsingDecl::using_decl_type x = UsingDecl::using_decl_var;
UsingDecl::inner y = x; UsingDecl::inner y = x;
@import using_decl.b;
void test_conflicting_2() {
use(conflicting_hidden_using_decl); // expected-error {{ambiguous}}
use(conflicting_hidden_using_decl_fn()); // expected-error {{ambiguous}}
use(conflicting_hidden_using_decl_var); // expected-error {{ambiguous}}
use(conflicting_hidden_using_decl_fn_2()); // expected-error {{ambiguous}}
use(conflicting_hidden_using_decl_var_2); // expected-error {{ambiguous}}
use(conflicting_hidden_using_decl_mixed_1); // ok, struct hidden
use(conflicting_hidden_using_decl_mixed_2); // expected-error {{ambiguous}}
use(conflicting_hidden_using_decl_mixed_3); // ok, struct hidden
use(conflicting_hidden_using_decl_mixed_4); // ok, struct hidden
use(conflicting_hidden_using_decl_mixed_5); // expected-error {{ambiguous}}
use(conflicting_hidden_using_decl_mixed_6); // ok, struct hidden
// expected-note@using-decl.cpp:* 7{{candidate}}
// expected-note@using-decl-b.h:* 7{{candidate}}
int conflicting_hidden_using_decl_mixed_1::*p1;
int conflicting_hidden_using_decl_mixed_3::*p3;
int conflicting_hidden_using_decl_mixed_4::*p4;
int conflicting_hidden_using_decl_mixed_6::*p6;
}