From: Alex Lorenz Date: Thu, 15 Jun 2017 21:19:01 +0000 (+0000) Subject: [index] Record C++17 global binding declarations X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4d2e73a5c6717d23f882848444920fec42c852f5;p=clang [index] Record C++17 global binding declarations The global C++17 binding declarations should be indexed as variable symbols. Differential Revision: https://reviews.llvm.org/D33920 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305508 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Index/IndexDecl.cpp b/lib/Index/IndexDecl.cpp index c4e9a1a10a..2162c039c4 100644 --- a/lib/Index/IndexDecl.cpp +++ b/lib/Index/IndexDecl.cpp @@ -293,6 +293,12 @@ public: return true; } + bool VisitDecompositionDecl(const DecompositionDecl *D) { + for (const auto *Binding : D->bindings()) + TRY_DECL(Binding, IndexCtx.handleDecl(Binding)); + return Base::VisitDecompositionDecl(D); + } + bool VisitFieldDecl(const FieldDecl *D) { SmallVector Relations; gatherTemplatePseudoOverrides(D, Relations); diff --git a/lib/Index/IndexSymbol.cpp b/lib/Index/IndexSymbol.cpp index 0b20970acc..bf358a3721 100644 --- a/lib/Index/IndexSymbol.cpp +++ b/lib/Index/IndexSymbol.cpp @@ -301,6 +301,10 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { Info.Kind = SymbolKind::TypeAlias; Info.Lang = SymbolLanguage::CXX; break; + case Decl::Binding: + Info.Kind = SymbolKind::Variable; + Info.Lang = SymbolLanguage::CXX; + break; default: break; } diff --git a/test/Index/Core/index-source.cpp b/test/Index/Core/index-source.cpp index 61b7b00463..10f2d8f777 100644 --- a/test/Index/Core/index-source.cpp +++ b/test/Index/Core/index-source.cpp @@ -1,4 +1,4 @@ -// RUN: c-index-test core -print-source-symbols -- %s -std=c++14 -target x86_64-apple-macosx10.7 | FileCheck %s +// RUN: c-index-test core -print-source-symbols -- %s -std=c++1z -target x86_64-apple-macosx10.7 | FileCheck %s // CHECK: [[@LINE+1]]:7 | class/C++ | Cls | [[Cls_USR:.*]] | | Def | rel: 0 class Cls { public: @@ -449,3 +449,29 @@ void staticAssertInFn() { // CHECK: [[@LINE-3]]:17 | struct/C++ | StaticAssertRef | c:@S@StaticAssertRef | | Ref,RelCont | rel: 1 // CHECK-NEXT: RelCont | staticAssertInFn | c:@F@staticAssertInFn# } + +namespace cpp17structuredBinding { + +struct Cpp17StructuredBinding { + int x, y; + + Cpp17StructuredBinding(int x, int y): x(x), y(y) { } +}; + +auto [structuredBinding1, structuredBinding2] = Cpp17StructuredBinding(Record::C, 0); +// CHECK: [[@LINE-1]]:7 | variable/C++ | structuredBinding1 | c:@N@cpp17structuredBinding@structuredBinding1 | | Decl,RelChild | rel: 1 +// CHECK-NEXT: RelChild | cpp17structuredBinding | c:@N@cpp17structuredBinding +// CHECK: [[@LINE-3]]:27 | variable/C++ | structuredBinding2 | c:@N@cpp17structuredBinding@structuredBinding2 | | Decl,RelChild | rel: 1 +// CHECK-NEXT: RelChild | cpp17structuredBinding | c:@N@cpp17structuredBinding + +void localStructuredBindingAndRef() { + int ref = structuredBinding1; +// CHECK: [[@LINE-1]]:13 | variable/C++ | structuredBinding1 | c:@N@cpp17structuredBinding@structuredBinding1 | | Ref,Read,RelCont | rel: 1 +// CHECK-NEXT: RelCont | localStructuredBindingAndRef | c:@N@cpp17structuredBinding@F@localStructuredBindingAndRef# + auto [localBinding1, localBinding2] = Cpp17StructuredBinding(ref, structuredBinding2); +// CHECK: [[@LINE-1]]:69 | variable/C++ | structuredBinding2 | c:@N@cpp17structuredBinding@structuredBinding2 | | Ref,Read,RelCont | rel: 1 +// CHECK-NEXT: RelCont | localStructuredBindingAndRef | c:@N@cpp17structuredBinding@F@localStructuredBindingAndRef# +// CHECK-NOT: localBinding +} + +}