From d65b3e4212588224f49a8be2ea2f0aac180dfc94 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Mon, 22 May 2017 14:39:39 +0000 Subject: [PATCH] [index] 'using namespace' declarations in functions should record the reference to the namespace rdar://32323190 llvm-svn: 303555 --- clang/lib/Index/IndexDecl.cpp | 8 ++++++-- clang/lib/Index/IndexSymbol.cpp | 2 ++ clang/test/Index/Core/index-source.cpp | 11 +++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/clang/lib/Index/IndexDecl.cpp b/clang/lib/Index/IndexDecl.cpp index 203862c..074e40fa 100644 --- a/clang/lib/Index/IndexDecl.cpp +++ b/clang/lib/Index/IndexDecl.cpp @@ -568,8 +568,12 @@ public: const DeclContext *DC = D->getDeclContext()->getRedeclContext(); const NamedDecl *Parent = dyn_cast(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(), diff --git a/clang/lib/Index/IndexSymbol.cpp b/clang/lib/Index/IndexSymbol.cpp index a108f86..0b20970 100644 --- a/clang/lib/Index/IndexSymbol.cpp +++ b/clang/lib/Index/IndexSymbol.cpp @@ -61,6 +61,8 @@ bool index::isFunctionLocalSymbol(const Decl *D) { if (isa(D)) return true; + if (isa(D)) + return false; if (!D->getParentFunctionOrMethod()) return false; diff --git a/clang/test/Index/Core/index-source.cpp b/clang/test/Index/Core/index-source.cpp index 9248e86..a8f3aa4 100644 --- a/clang/test/Index/Core/index-source.cpp +++ b/clang/test/Index/Core/index-source.cpp @@ -339,3 +339,14 @@ void ::ns::inner::func() { // CHECK: [[@LINE-1]]:3 | namespace/C++ | ns | c:@N@ns | | Ref,RelCont | rel: 1 // CHECK: [[@LINE-2]]:7 | namespace-alias/C++ | innerAlias | c:@N@ns@NA@innerAlias | | Ref,RelCont | rel: 1 } + +void innerUsingNamespace() { + using namespace ns; +// CHECK: [[@LINE-1]]:19 | namespace/C++ | ns | c:@N@ns | | Ref,RelCont | rel: 1 + { + using namespace ns::innerAlias; +// CHECK: [[@LINE-1]]:25 | namespace-alias/C++ | innerAlias | c:@N@ns@NA@innerAlias | | Ref,RelCont | rel: 1 +// CHECK: [[@LINE-2]]:21 | namespace/C++ | ns | c:@N@ns | | Ref,RelCont | rel: 1 +// CHECK-NOT: [[@LINE-3]]:21 + } +} -- 2.7.4