diff options
| author | Nikolai Kosjar <nikolai.kosjar@qt.io> | 2019-05-21 09:21:35 +0000 |
|---|---|---|
| committer | Nikolai Kosjar <nikolai.kosjar@qt.io> | 2019-05-21 09:21:35 +0000 |
| commit | 2eebf4d939b65650ba14ec062fe4be750fa347e1 (patch) | |
| tree | d0663bb42ba3931e72a62be2febd0c29d174d296 | |
| parent | 8fcf012693aeb25e29430bcbbf6a60f28f440357 (diff) | |
| download | bcm5719-llvm-2eebf4d939b65650ba14ec062fe4be750fa347e1.tar.gz bcm5719-llvm-2eebf4d939b65650ba14ec062fe4be750fa347e1.zip | |
[libclang] visit c++14 lambda capture init expressions
Patch by Milian Wolff.
Differential Revision: https://reviews.llvm.org/D60672
llvm-svn: 361234
| -rw-r--r-- | clang/test/Index/cxx14-lambdas.cpp | 38 | ||||
| -rw-r--r-- | clang/tools/libclang/CIndex.cpp | 8 |
2 files changed, 44 insertions, 2 deletions
diff --git a/clang/test/Index/cxx14-lambdas.cpp b/clang/test/Index/cxx14-lambdas.cpp new file mode 100644 index 00000000000..abca65b518b --- /dev/null +++ b/clang/test/Index/cxx14-lambdas.cpp @@ -0,0 +1,38 @@ +// Test is line- and column-sensitive; see below. + +typedef int Integer; +struct X { + void f() { + int localA, localB; + auto lambda = [ptr = &localA, copy = localB] (Integer x) -> Integer { + return *ptr + copy + x; + }; + } +}; + +// RUN: c-index-test -test-load-source all -std=c++14 %s | FileCheck -check-prefix=CHECK-LOAD %s +// CHECK-LOAD: cxx14-lambdas.cpp:7:5: DeclStmt= Extent=[7:5 - 9:7] +// CHECK-LOAD: cxx14-lambdas.cpp:7:10: VarDecl=lambda:7:10 (Definition) Extent=[7:5 - 9:6] +// CHECK-LOAD: cxx14-lambdas.cpp:7:19: UnexposedExpr= Extent=[7:19 - 9:6] +// CHECK-LOAD: cxx14-lambdas.cpp:7:19: CallExpr= Extent=[7:19 - 9:6] +// CHECK-LOAD: cxx14-lambdas.cpp:7:19: UnexposedExpr= Extent=[7:19 - 9:6] +// CHECK-LOAD: cxx14-lambdas.cpp:7:19: LambdaExpr= Extent=[7:19 - 9:6] +// CHECK-LOAD: cxx14-lambdas.cpp:7:20: VariableRef=ptr:7:20 Extent=[7:20 - 7:23] +// CHECK-LOAD: cxx14-lambdas.cpp:7:35: VariableRef=copy:7:35 Extent=[7:35 - 7:39] +// CHECK-LOAD: cxx14-lambdas.cpp:7:27: DeclRefExpr=localA:6:9 Extent=[7:27 - 7:33] +// CHECK-LOAD: cxx14-lambdas.cpp:7:42: DeclRefExpr=localB:6:17 Extent=[7:42 - 7:48] +// CHECK-LOAD: cxx14-lambdas.cpp:7:59: ParmDecl=x:7:59 (Definition) Extent=[7:51 - 7:60] +// CHECK-LOAD: cxx14-lambdas.cpp:7:51: TypeRef=Integer:3:13 Extent=[7:51 - 7:58] +// CHECK-LOAD: cxx14-lambdas.cpp:7:65: TypeRef=Integer:3:13 Extent=[7:65 - 7:72] +// CHECK-LOAD: cxx14-lambdas.cpp:7:73: CompoundStmt= Extent=[7:73 - 9:6] +// 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: ptr | USR: c:cxx14-lambdas.cpp@139@S@X@F@f#@Sa@F@operator()#I#1@ptr | lang: C | cursor: VariableRef=ptr:7:20 | loc: 7:20 +// CHECK-INDEX: [indexEntityReference]: kind: variable | name: copy | USR: c:cxx14-lambdas.cpp@154@S@X@F@f#@Sa@F@operator()#I#1@copy | lang: C | cursor: VariableRef=copy:7:35 | loc: 7:35 +// CHECK-INDEX: [indexDeclaration]: kind: variable | name: x | USR: c:cxx14-lambdas.cpp@170@S@X@F@f#@Sa@F@operator()#I#1@x | lang: C | cursor: ParmDecl=x:7:59 (Definition) | loc: 7:59 +// CHECK-INDEX: [indexEntityReference]: kind: typedef | name: Integer | USR: c:cxx14-lambdas.cpp@T@Integer | lang: C | cursor: TypeRef=Integer:3:13 | loc: 7:51 +// CHECK-INDEX: [indexEntityReference]: kind: typedef | name: Integer | USR: c:cxx14-lambdas.cpp@T@Integer | lang: C | cursor: TypeRef=Integer:3:13 | loc: 7:65 +// CHECK-INDEX: [indexEntityReference]: kind: variable | name: ptr | USR: c:cxx14-lambdas.cpp@139@S@X@F@f#@Sa@F@operator()#I#1@ptr | lang: C | cursor: DeclRefExpr=ptr:7:20 | loc: 8:15 +// CHECK-INDEX: [indexEntityReference]: kind: variable | name: copy | USR: c:cxx14-lambdas.cpp@154@S@X@F@f#@Sa@F@operator()#I#1@copy | lang: C | cursor: DeclRefExpr=copy:7:35 | loc: 8:21 +// CHECK-INDEX: [indexEntityReference]: kind: variable | name: x | USR: c:cxx14-lambdas.cpp@170@S@X@F@f#@Sa@F@operator()#I#1@x | lang: C | cursor: DeclRefExpr=x:7:59 | loc: 8:28 diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index 715618c3c0f..f065802467a 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -3134,12 +3134,11 @@ bool CursorVisitor::RunVisitorWorkList(VisitorWorkList &WL) { } case VisitorJob::LambdaExprPartsKind: { - // Visit captures. + // Visit non-init captures. const LambdaExpr *E = cast<LambdaExprParts>(&LI)->get(); for (LambdaExpr::capture_iterator C = E->explicit_capture_begin(), CEnd = E->explicit_capture_end(); C != CEnd; ++C) { - // FIXME: Lambda init-captures. if (!C->capturesVariable()) continue; @@ -3148,6 +3147,11 @@ bool CursorVisitor::RunVisitorWorkList(VisitorWorkList &WL) { TU))) return true; } + // Visit init captures + for (auto InitExpr : E->capture_inits()) { + if (Visit(InitExpr)) + return true; + } TypeLoc TL = E->getCallOperator()->getTypeSourceInfo()->getTypeLoc(); // Visit parameters and return type, if present. |

