<div dir="ltr">I should add: the test is courtesy of Vassil Vassilev. Thanks!</div><div class="gmail_extra"><br><div class="gmail_quote">On 30 October 2017 at 15:38, Richard Smith via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rsmith<br>
Date: Mon Oct 30 15:38:20 2017<br>
New Revision: 316965<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=316965&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=316965&view=rev</a><br>
Log:<br>
[modules] Retain multiple using-directives in the same scope even if they name the same namespace.<br>
<br>
They might have different visibility, and thus discarding all but one of them<br>
can result in rejecting valid code. Also fix name lookup to cope with multiple<br>
using-directives being found that denote the same namespace, where some are not<br>
visible -- don't cache an "already visited" state for a using-directive that we<br>
didn't visit because it was hidden.<br>
<br>
Added:<br>
cfe/trunk/test/Modules/using-<wbr>directive-redecl.cpp<br>
Modified:<br>
cfe/trunk/lib/AST/Decl.cpp<br>
cfe/trunk/lib/Sema/SemaLookup.<wbr>cpp<br>
<br>
Modified: cfe/trunk/lib/AST/Decl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=316965&r1=316964&r2=316965&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/AST/<wbr>Decl.cpp?rev=316965&r1=316964&<wbr>r2=316965&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/AST/Decl.cpp (original)<br>
+++ cfe/trunk/lib/AST/Decl.cpp Mon Oct 30 15:38:20 2017<br>
@@ -1597,14 +1597,6 @@ bool NamedDecl::<wbr>declarationReplaces(Name<br>
cast<UnresolvedUsingValueDecl><wbr>(OldD)->getQualifier());<br>
}<br>
<br>
- // UsingDirectiveDecl's are not really NamedDecl's, and all have same name.<br>
- // They can be replaced if they nominate the same namespace.<br>
- // FIXME: Is this true even if they have different module visibility?<br>
- if (auto *UD = dyn_cast<UsingDirectiveDecl>(<wbr>this))<br>
- return UD->getNominatedNamespace()-><wbr>getOriginalNamespace() ==<br>
- cast<UsingDirectiveDecl>(OldD)<wbr>->getNominatedNamespace()<br>
- ->getOriginalNamespace();<br>
-<br>
if (isRedeclarable(getKind())) {<br>
if (getCanonicalDecl() != OldD->getCanonicalDecl())<br>
return false;<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaLookup.<wbr>cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=316965&r1=316964&r2=316965&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Sema/<wbr>SemaLookup.cpp?rev=316965&r1=<wbr>316964&r2=316965&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Sema/SemaLookup.<wbr>cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaLookup.<wbr>cpp Mon Oct 30 15:38:20 2017<br>
@@ -155,7 +155,7 @@ namespace {<br>
while (true) {<br>
for (auto UD : DC->using_directives()) {<br>
DeclContext *NS = UD->getNominatedNamespace();<br>
- if (visited.insert(NS).second && SemaRef.isVisible(UD)) {<br>
+ if (SemaRef.isVisible(UD) && visited.insert(NS).second) {<br>
addUsingDirective(UD, EffectiveDC);<br>
queue.push_back(NS);<br>
}<br>
@@ -1883,7 +1883,7 @@ static bool LookupQualifiedNameInUsingDi<br>
// with its using-children.<br>
for (auto *I : StartDC->using_directives()) {<br>
NamespaceDecl *ND = I->getNominatedNamespace()-><wbr>getOriginalNamespace();<br>
- if (Visited.insert(ND).second && S.isVisible(I))<br>
+ if (S.isVisible(I) && Visited.insert(ND).second)<br>
Queue.push_back(ND);<br>
}<br>
<br>
@@ -1931,7 +1931,7 @@ static bool LookupQualifiedNameInUsingDi<br>
<br>
for (auto I : ND->using_directives()) {<br>
NamespaceDecl *Nom = I->getNominatedNamespace();<br>
- if (Visited.insert(Nom).second && S.isVisible(I))<br>
+ if (S.isVisible(I) && Visited.insert(Nom).second)<br>
Queue.push_back(Nom);<br>
}<br>
}<br>
<br>
Added: cfe/trunk/test/Modules/using-<wbr>directive-redecl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/using-directive-redecl.cpp?rev=316965&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/<wbr>Modules/using-directive-<wbr>redecl.cpp?rev=316965&view=<wbr>auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/Modules/using-<wbr>directive-redecl.cpp (added)<br>
+++ cfe/trunk/test/Modules/using-<wbr>directive-redecl.cpp Mon Oct 30 15:38:20 2017<br>
@@ -0,0 +1,37 @@<br>
+// RUN: %clang_cc1 -fmodules -fmodules-local-submodule-<wbr>visibility -verify %s<br>
+// expected-no-diagnostics<br>
+#pragma clang module build M<br>
+module M { module TDFNodes {} module TDFInterface {} }<br>
+#pragma clang module contents<br>
+ // TDFNodes<br>
+ #pragma clang module begin M.TDFNodes<br>
+ namespace Detail {<br>
+ namespace TDF {<br>
+ class TLoopManager {};<br>
+ }<br>
+ }<br>
+ namespace Internal {<br>
+ namespace TDF {<br>
+ using namespace Detail::TDF;<br>
+ }<br>
+ }<br>
+ #pragma clang module end<br>
+<br>
+ // TDFInterface<br>
+ #pragma clang module begin M.TDFInterface<br>
+ #pragma clang module import M.TDFNodes<br>
+ namespace Internal {<br>
+ namespace TDF {<br>
+ using namespace Detail::TDF;<br>
+ }<br>
+ }<br>
+ #pragma clang module end<br>
+<br>
+#pragma clang module endbuild<br>
+<br>
+#pragma clang module import M.TDFNodes<br>
+namespace Internal {<br>
+ namespace TDF {<br>
+ TLoopManager * use;<br>
+ }<br>
+}<br>
<br>
<br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>