r303555 - [index] 'using namespace' declarations in functions should record

Alex Lorenz via cfe-commits cfe-commits at lists.llvm.org
Mon May 22 07:39:39 PDT 2017


Author: arphaman
Date: Mon May 22 09:39:39 2017
New Revision: 303555

URL: http://llvm.org/viewvc/llvm-project?rev=303555&view=rev
Log:
[index] 'using namespace' declarations in functions should record
the reference to the namespace

rdar://32323190

Modified:
    cfe/trunk/lib/Index/IndexDecl.cpp
    cfe/trunk/lib/Index/IndexSymbol.cpp
    cfe/trunk/test/Index/Core/index-source.cpp

Modified: cfe/trunk/lib/Index/IndexDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexDecl.cpp?rev=303555&r1=303554&r2=303555&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexDecl.cpp (original)
+++ cfe/trunk/lib/Index/IndexDecl.cpp Mon May 22 09:39:39 2017
@@ -568,8 +568,12 @@ public:
     const DeclContext *DC = D->getDeclContext()->getRedeclContext();
     const NamedDecl *Parent = dyn_cast<NamedDecl>(DC);
 
-    IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent,
-                                         D->getLexicalDeclContext());
+    // NNS for the local 'using namespace' directives is visited by the body
+    // visitor.
+    if (!D->getParentFunctionOrMethod())
+      IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent,
+                                           D->getLexicalDeclContext());
+
     return IndexCtx.handleReference(D->getNominatedNamespaceAsWritten(),
                                     D->getLocation(), Parent,
                                     D->getLexicalDeclContext(),

Modified: cfe/trunk/lib/Index/IndexSymbol.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexSymbol.cpp?rev=303555&r1=303554&r2=303555&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexSymbol.cpp (original)
+++ cfe/trunk/lib/Index/IndexSymbol.cpp Mon May 22 09:39:39 2017
@@ -61,6 +61,8 @@ bool index::isFunctionLocalSymbol(const
   if (isa<ObjCTypeParamDecl>(D))
     return true;
 
+  if (isa<UsingDirectiveDecl>(D))
+    return false;
   if (!D->getParentFunctionOrMethod())
     return false;
 

Modified: cfe/trunk/test/Index/Core/index-source.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-source.cpp?rev=303555&r1=303554&r2=303555&view=diff
==============================================================================
--- cfe/trunk/test/Index/Core/index-source.cpp (original)
+++ cfe/trunk/test/Index/Core/index-source.cpp Mon May 22 09:39:39 2017
@@ -339,3 +339,14 @@ void ::ns::inner::func() {
 // CHECK: [[@LINE-1]]:3 | namespace/C++ | ns | c:@N at ns | <no-cgname> | Ref,RelCont | rel: 1
 // CHECK: [[@LINE-2]]:7 | namespace-alias/C++ | innerAlias | c:@N at ns@NA at innerAlias | <no-cgname> | Ref,RelCont | rel: 1
 }
+
+void innerUsingNamespace() {
+  using namespace ns;
+// CHECK: [[@LINE-1]]:19 | namespace/C++ | ns | c:@N at ns | <no-cgname> | Ref,RelCont | rel: 1
+  {
+    using namespace ns::innerAlias;
+// CHECK: [[@LINE-1]]:25 | namespace-alias/C++ | innerAlias | c:@N at ns@NA at innerAlias | <no-cgname> | Ref,RelCont | rel: 1
+// CHECK: [[@LINE-2]]:21 | namespace/C++ | ns | c:@N at ns | <no-cgname> | Ref,RelCont | rel: 1
+// CHECK-NOT: [[@LINE-3]]:21
+  }
+}




More information about the cfe-commits mailing list