r247654 - [modules] A using-declaration doesn't introduce a new entity, just a new name
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 14 18:28:56 PDT 2015
Author: rsmith
Date: Mon Sep 14 20:28:55 2015
New Revision: 247654
URL: http://llvm.org/viewvc/llvm-project?rev=247654&view=rev
Log:
[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).
Modified:
cfe/trunk/include/clang/Sema/Lookup.h
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/Modules/Inputs/using-decl-b.h
cfe/trunk/test/Modules/using-decl.cpp
Modified: cfe/trunk/include/clang/Sema/Lookup.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Lookup.h?rev=247654&r1=247653&r2=247654&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Lookup.h (original)
+++ cfe/trunk/include/clang/Sema/Lookup.h Mon Sep 14 20:28:55 2015
@@ -237,6 +237,11 @@ public:
/// \brief Determine whether this lookup is permitted to see hidden
/// declarations, such as those in modules that have not yet been imported.
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 &&
(AllowHiddenInternal || ND->isExternallyVisible())) ||
LookupKind == Sema::LookupTagName;
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=247654&r1=247653&r2=247654&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Sep 14 20:28:55 2015
@@ -7821,7 +7821,8 @@ bool Sema::CheckUsingShadowDecl(UsingDec
FoundEquivalentDecl = true;
}
- (isa<TagDecl>(D) ? Tag : NonTag) = D;
+ if (isVisible(D))
+ (isa<TagDecl>(D) ? Tag : NonTag) = D;
}
if (FoundEquivalentDecl)
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=247654&r1=247653&r2=247654&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Mon Sep 14 20:28:55 2015
@@ -896,6 +896,11 @@ Sema::CheckOverload(Scope *S, FunctionDe
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,
// we'll need to use slightly different rules for matching.
// Essentially, these rules are the normal rules, except that
Modified: cfe/trunk/test/Modules/Inputs/using-decl-b.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/using-decl-b.h?rev=247654&r1=247653&r2=247654&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/using-decl-b.h (original)
+++ cfe/trunk/test/Modules/Inputs/using-decl-b.h Mon Sep 14 20:28:55 2015
@@ -9,3 +9,29 @@ namespace UsingDecl {
using ::using_decl_type;
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 {};
Modified: cfe/trunk/test/Modules/using-decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/using-decl.cpp?rev=247654&r1=247653&r2=247654&view=diff
==============================================================================
--- cfe/trunk/test/Modules/using-decl.cpp (original)
+++ cfe/trunk/test/Modules/using-decl.cpp Mon Sep 14 20:28:55 2015
@@ -1,8 +1,80 @@
// 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;
+#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
+ at import using_decl.a;
+#endif
-// expected-no-diagnostics
UsingDecl::using_decl_type x = UsingDecl::using_decl_var;
UsingDecl::inner y = x;
+
+ at 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 at using-decl.cpp:* 7{{candidate}}
+ // expected-note at 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;
+}
More information about the cfe-commits
mailing list