[PATCH] D87257: [clang] Traverse init-captures while indexing
Nathan Ridge via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 20 15:47:06 PDT 2020
nridge updated this revision to Diff 293040.
nridge added a comment.
Add clang test
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D87257/new/
https://reviews.llvm.org/D87257
Files:
clang-tools-extra/clangd/unittests/XRefsTests.cpp
clang/lib/Index/IndexBody.cpp
clang/test/Index/cxx14-lambdas.cpp
Index: clang/test/Index/cxx14-lambdas.cpp
===================================================================
--- clang/test/Index/cxx14-lambdas.cpp
+++ clang/test/Index/cxx14-lambdas.cpp
@@ -28,7 +28,9 @@
// CHECK-LOAD: cxx14-lambdas.cpp:8:7: ReturnStmt= Extent=[8:7 - 8:29]
// RUN: env CINDEXTEST_INDEXLOCALSYMBOLS=1 c-index-test -index-file -std=c++14 %s | FileCheck -check-prefix=CHECK-INDEX %s
+// CHECK-INDEX: [indexEntityReference]: kind: variable | name: localA | USR: c:cxx14-lambdas.cpp at 100@S at X@F at f#@localA | lang: C | cursor: DeclRefExpr=localA:6:9 | loc: 7:27
// CHECK-INDEX: [indexEntityReference]: kind: variable | name: ptr | USR: c:cxx14-lambdas.cpp at 139@S at X@F at f#@Sa at F@operator()#I#1 at ptr | lang: C | cursor: VariableRef=ptr:7:20 | loc: 7:20
+// CHECK-INDEX: [indexEntityReference]: kind: variable | name: localB | USR: c:cxx14-lambdas.cpp at 100@S at X@F at f#@localB | lang: C | cursor: DeclRefExpr=localB:6:17 | loc: 7:42
// CHECK-INDEX: [indexEntityReference]: kind: variable | name: copy | USR: c:cxx14-lambdas.cpp at 154@S at X@F at f#@Sa at F@operator()#I#1 at copy | lang: C | cursor: VariableRef=copy:7:35 | loc: 7:35
// CHECK-INDEX: [indexDeclaration]: kind: variable | name: x | USR: c:cxx14-lambdas.cpp at 170@S at X@F at f#@Sa at F@operator()#I#1 at x | lang: C | cursor: ParmDecl=x:7:59 (Definition) | loc: 7:59
// CHECK-INDEX: [indexEntityReference]: kind: typedef | name: Integer | USR: c:cxx14-lambdas.cpp at T@Integer | lang: C | cursor: TypeRef=Integer:3:13 | loc: 7:51
Index: clang/lib/Index/IndexBody.cpp
===================================================================
--- clang/lib/Index/IndexBody.cpp
+++ clang/lib/Index/IndexBody.cpp
@@ -391,11 +391,13 @@
if (C->capturesThis() || C->capturesVLAType())
return true;
+ if (!base::TraverseStmt(Init))
+ return false;
+
if (C->capturesVariable() && IndexCtx.shouldIndexFunctionLocalSymbols())
return IndexCtx.handleReference(C->getCapturedVar(), C->getLocation(),
Parent, ParentDC, SymbolRoleSet());
- // FIXME: Lambda init-captures.
return true;
}
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1589,6 +1589,12 @@
[[Vector]]<int> x2;
Vector<double> y;
)cpp",
+ R"cpp(// Lambda capture initializer
+ void foo() {
+ int [[w^aldo]] = 42;
+ auto lambda = [x = [[waldo]]](){};
+ }
+ )cpp",
};
for (const char *Test : Tests) {
Annotations T(Test);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87257.293040.patch
Type: text/x-patch
Size: 2654 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200920/79a2357a/attachment-0001.bin>
More information about the cfe-commits
mailing list