From: Alex Lorenz Date: Mon, 22 May 2017 15:17:44 +0000 (+0000) Subject: [index] Visit the default argument values in function definitions X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=546e0b992228ee13196b42e465a773bb7fc89a2b;p=clang [index] Visit the default argument values in function definitions rdar://32323315 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@303559 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Index/IndexDecl.cpp b/lib/Index/IndexDecl.cpp index 074e40fad6..726568a426 100644 --- a/lib/Index/IndexDecl.cpp +++ b/lib/Index/IndexDecl.cpp @@ -98,6 +98,17 @@ public: } } } + } else { + // Index the default parameter value for function definitions. + if (const auto *FD = dyn_cast(D)) { + if (FD->isThisDeclarationADefinition()) { + for (const auto *PV : FD->parameters()) { + if (PV->hasDefaultArg() && !PV->hasUninstantiatedDefaultArg() && + !PV->hasUnparsedDefaultArg()) + IndexCtx.indexBody(PV->getDefaultArg(), D); + } + } + } } } diff --git a/test/Index/Core/index-source.cpp b/test/Index/Core/index-source.cpp index a8f3aa49f9..5f2044e803 100644 --- a/test/Index/Core/index-source.cpp +++ b/test/Index/Core/index-source.cpp @@ -1,7 +1,7 @@ // RUN: c-index-test core -print-source-symbols -- %s -std=c++14 -target x86_64-apple-macosx10.7 | FileCheck %s // CHECK: [[@LINE+1]]:7 | class/C++ | Cls | [[Cls_USR:.*]] | | Def | rel: 0 -class Cls { +class Cls { public: // CHECK: [[@LINE+3]]:3 | constructor/C++ | Cls | c:@S@Cls@F@Cls#I# | __ZN3ClsC1Ei | Decl,RelChild | rel: 1 // CHECK-NEXT: RelChild | Cls | c:@S@Cls // CHECK: [[@LINE+1]]:3 | class/C++ | Cls | c:@S@Cls | | Ref,RelCont | rel: 1 @@ -350,3 +350,19 @@ void innerUsingNamespace() { // CHECK-NOT: [[@LINE-3]]:21 } } + +void indexDefaultValueInDefn(Cls cls = Cls(gvi), Record param = Record()) { +// CHECK: [[@LINE-1]]:40 | class/C++ | Cls | c:@S@Cls | | Ref,RelCont | rel: 1 +// CHECK: [[@LINE-2]]:44 | variable/C | gvi | c:@gvi | _gvi | Ref,Read,RelCont | rel: 1 +// CHECK-NOT: [[@LINE-3]]:44 +// CHECK: [[@LINE-4]]:65 | struct/C++ | Record | c:@S@Record | | Ref,RelCont | rel: 1 +// CHECK-NOT: [[@LINE-5]]:65 +} + +template