ioeric created this revision. ... in qualified code completion and decl lookup.
https://reviews.llvm.org/D40562 Files: lib/Sema/SemaCodeComplete.cpp lib/Sema/SemaLookup.cpp test/CodeCompletion/ignore-global-decls.cpp Index: test/CodeCompletion/ignore-global-decls.cpp =================================================================== --- /dev/null +++ test/CodeCompletion/ignore-global-decls.cpp @@ -0,0 +1,20 @@ +namespace ns { + struct bar { + }; + + struct baz { + }; + + int func(int a, bar b, baz c); +} + +void test() { + ns:: +// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:12:7 %s -o - | FileCheck %s --check-prefix=CHECK-1 +// CHECK-1-DAG: COMPLETION: bar : bar +// CHECK-1-DAG: COMPLETION: baz : baz +// CHECK-1-DAG: COMPLETION: func : [#int#]func(<#int a#>, <#bar b#>, <#baz c#>) + +// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:12:7 -no-code-completion-globals %s -o - | FileCheck %s -allow-empty --check-prefix=CHECK-EMPTY +// CHECK-EMPTY: {{^}}{{$}} +} Index: lib/Sema/SemaLookup.cpp =================================================================== --- lib/Sema/SemaLookup.cpp +++ lib/Sema/SemaLookup.cpp @@ -3785,8 +3785,12 @@ LookupResult Result(*this, DeclarationName(), SourceLocation(), Kind); Result.setAllowHidden(Consumer.includeHiddenDecls()); VisibleDeclsRecord Visited; - if (!IncludeGlobalScope) + if (!IncludeGlobalScope) { Visited.visitedContext(Context.getTranslationUnitDecl()); + // Declarations in namespace are also considered global. + if (Ctx->isNamespace() || Ctx->isTranslationUnit()) + Visited.visitedContext(Ctx); + } ShadowContextRAII Shadow(Visited); ::LookupVisibleDecls(Ctx, Result, /*QualifiedNameLookup=*/true, /*InBaseClass=*/false, Consumer, Visited, Index: lib/Sema/SemaCodeComplete.cpp =================================================================== --- lib/Sema/SemaCodeComplete.cpp +++ lib/Sema/SemaCodeComplete.cpp @@ -4639,7 +4639,7 @@ CodeCompletionDeclConsumer Consumer(Results, CurContext); LookupVisibleDecls(Ctx, LookupOrdinaryName, Consumer, - /*IncludeGlobalScope=*/true, + CodeCompleter->includeGlobals(), /*IncludeDependentBases=*/true); HandleCodeCompleteResults(this, CodeCompleter,
Index: test/CodeCompletion/ignore-global-decls.cpp =================================================================== --- /dev/null +++ test/CodeCompletion/ignore-global-decls.cpp @@ -0,0 +1,20 @@ +namespace ns { + struct bar { + }; + + struct baz { + }; + + int func(int a, bar b, baz c); +} + +void test() { + ns:: +// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:12:7 %s -o - | FileCheck %s --check-prefix=CHECK-1 +// CHECK-1-DAG: COMPLETION: bar : bar +// CHECK-1-DAG: COMPLETION: baz : baz +// CHECK-1-DAG: COMPLETION: func : [#int#]func(<#int a#>, <#bar b#>, <#baz c#>) + +// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:12:7 -no-code-completion-globals %s -o - | FileCheck %s -allow-empty --check-prefix=CHECK-EMPTY +// CHECK-EMPTY: {{^}}{{$}} +} Index: lib/Sema/SemaLookup.cpp =================================================================== --- lib/Sema/SemaLookup.cpp +++ lib/Sema/SemaLookup.cpp @@ -3785,8 +3785,12 @@ LookupResult Result(*this, DeclarationName(), SourceLocation(), Kind); Result.setAllowHidden(Consumer.includeHiddenDecls()); VisibleDeclsRecord Visited; - if (!IncludeGlobalScope) + if (!IncludeGlobalScope) { Visited.visitedContext(Context.getTranslationUnitDecl()); + // Declarations in namespace are also considered global. + if (Ctx->isNamespace() || Ctx->isTranslationUnit()) + Visited.visitedContext(Ctx); + } ShadowContextRAII Shadow(Visited); ::LookupVisibleDecls(Ctx, Result, /*QualifiedNameLookup=*/true, /*InBaseClass=*/false, Consumer, Visited, Index: lib/Sema/SemaCodeComplete.cpp =================================================================== --- lib/Sema/SemaCodeComplete.cpp +++ lib/Sema/SemaCodeComplete.cpp @@ -4639,7 +4639,7 @@ CodeCompletionDeclConsumer Consumer(Results, CurContext); LookupVisibleDecls(Ctx, LookupOrdinaryName, Consumer, - /*IncludeGlobalScope=*/true, + CodeCompleter->includeGlobals(), /*IncludeDependentBases=*/true); HandleCodeCompleteResults(this, CodeCompleter,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits