[index] 'using namespace' declarations in functions should record
authorAlex Lorenz <arphaman@gmail.com>
Mon, 22 May 2017 14:39:39 +0000 (14:39 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Mon, 22 May 2017 14:39:39 +0000 (14:39 +0000)
the reference to the namespace

rdar://32323190

llvm-svn: 303555

clang/lib/Index/IndexDecl.cpp
clang/lib/Index/IndexSymbol.cpp
clang/test/Index/Core/index-source.cpp

index 203862c..074e40f 100644 (file)
@@ -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(),
index a108f86..0b20970 100644 (file)
@@ -61,6 +61,8 @@ bool index::isFunctionLocalSymbol(const Decl *D) {
   if (isa<ObjCTypeParamDecl>(D))
     return true;
 
+  if (isa<UsingDirectiveDecl>(D))
+    return false;
   if (!D->getParentFunctionOrMethod())
     return false;
 
index 9248e86..a8f3aa4 100644 (file)
@@ -339,3 +339,14 @@ void ::ns::inner::func() {
 // CHECK: [[@LINE-1]]:3 | namespace/C++ | ns | c:@N@ns | <no-cgname> | Ref,RelCont | rel: 1
 // CHECK: [[@LINE-2]]:7 | namespace-alias/C++ | innerAlias | c:@N@ns@NA@innerAlias | <no-cgname> | Ref,RelCont | rel: 1
 }
+
+void innerUsingNamespace() {
+  using namespace ns;
+// CHECK: [[@LINE-1]]:19 | namespace/C++ | ns | c:@N@ns | <no-cgname> | Ref,RelCont | rel: 1
+  {
+    using namespace ns::innerAlias;
+// CHECK: [[@LINE-1]]:25 | namespace-alias/C++ | innerAlias | c:@N@ns@NA@innerAlias | <no-cgname> | Ref,RelCont | rel: 1
+// CHECK: [[@LINE-2]]:21 | namespace/C++ | ns | c:@N@ns | <no-cgname> | Ref,RelCont | rel: 1
+// CHECK-NOT: [[@LINE-3]]:21
+  }
+}