Skip to content

Commit 31bce53

Browse files
test: Add type & capture tests for lambdas (#124)
1 parent eaed532 commit 31bce53

File tree

4 files changed

+63
-6
lines changed

4 files changed

+63
-6
lines changed

test/index/types/types.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// extra-args: -std=c++20
12
// format-options: showDocs
23

34
#include "types.h"
@@ -114,3 +115,12 @@ class DiamondBase {};
114115
class Derived1 : public virtual DiamondBase {};
115116
class Derived2 : public virtual DiamondBase {};
116117
class Join : public Derived1, public Derived2 {};
118+
119+
struct L {};
120+
auto trailing_return_type() -> L {
121+
// Explicit template param list on lambda needs C++20
122+
auto ignore_first = []<class T>(T, L l) -> L {
123+
return l;
124+
};
125+
return ignore_first("", L{});
126+
}

test/index/types/types.snapshot.cc

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// extra-args: -std=c++20
12
// format-options: showDocs
23

34
#include "types.h"
@@ -106,14 +107,14 @@
106107
}
107108

108109
#define VISIT(_name) Visit##_name
109-
// ^^^^^ definition [..] `types.cc:69:9`!
110+
// ^^^^^ definition [..] `types.cc:70:9`!
110111

111112
enum VISIT(Sightseeing) {
112-
// ^^^^^ reference [..] `types.cc:69:9`!
113+
// ^^^^^ reference [..] `types.cc:70:9`!
113114
// ^^^^^ definition [..] VisitSightseeing#
114115
VISIT(Museum),
115116
// ^^^^^ definition [..] VisitMuseum.
116-
// ^^^^^ reference [..] `types.cc:69:9`!
117+
// ^^^^^ reference [..] `types.cc:70:9`!
117118
};
118119

119120
// Regression test for https://github.com/sourcegraph/scip-clang/issues/105
@@ -147,13 +148,13 @@
147148
// ^ reference [..] E#
148149
// ^^ reference [..] E#E0.
149150
#define QUALIFIED(enum_name, case_name) enum_name::case_name;
150-
// ^^^^^^^^^ definition [..] `types.cc:90:9`!
151+
// ^^^^^^^^^ definition [..] `types.cc:91:9`!
151152
(void)QUALIFIED(E, E0);
152153
// ^^^^^^^^^ reference [..] E#
153154
// ^^^^^^^^^ reference [..] E#E0.
154-
// ^^^^^^^^^ reference [..] `types.cc:90:9`!
155+
// ^^^^^^^^^ reference [..] `types.cc:91:9`!
155156
#undef QUALIFIED
156-
// ^^^^^^^^^ reference [..] `types.cc:90:9`!
157+
// ^^^^^^^^^ reference [..] `types.cc:91:9`!
157158
}
158159

159160
/// Restating what's already implied by the name
@@ -202,3 +203,21 @@
202203
// relation implementation [..] Derived2#
203204
// ^^^^^^^^ reference [..] Derived1#
204205
// ^^^^^^^^ reference [..] Derived2#
206+
207+
struct L {};
208+
// ^ definition [..] L#
209+
auto trailing_return_type() -> L {
210+
// ^ reference [..] L#
211+
// Explicit template param list on lambda needs C++20
212+
auto ignore_first = []<class T>(T, L l) -> L {
213+
// ^^^^^^^^^^^^ definition local 0
214+
// ^ reference [..] L#
215+
// ^ definition local 1
216+
// ^ reference [..] L#
217+
return l;
218+
// ^ reference local 1
219+
};
220+
return ignore_first("", L{});
221+
// ^^^^^^^^^^^^ reference local 0
222+
// ^ reference [..] L#
223+
}

test/index/vars/vars.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,12 @@ struct S {
1919
int f(S s) {
2020
return s.x + S::y;
2121
}
22+
23+
void lambdas() {
24+
int x = 0;
25+
int y = 1;
26+
auto add = [&x, y](int z) mutable {
27+
y += z;
28+
x += y;
29+
};
30+
}

test/index/vars/vars.snapshot.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,22 @@
3939
return s.x + S::y;
4040
// ^ reference local 8
4141
}
42+
43+
void lambdas() {
44+
int x = 0;
45+
// ^ definition local 9
46+
int y = 1;
47+
// ^ definition local 10
48+
auto add = [&x, y](int z) mutable {
49+
// ^^^ definition local 11
50+
// ^ reference local 9
51+
// ^ reference local 10
52+
// ^ definition local 12
53+
y += z;
54+
// ^ reference local 10
55+
// ^ reference local 12
56+
x += y;
57+
// ^ reference local 9
58+
// ^ reference local 10
59+
};
60+
}

0 commit comments

Comments
 (0)