Skip to content

Commit 5bef9f7

Browse files
committed
C++: test for resolving specialisations dependent on template aliases
1 parent f904aed commit 5bef9f7

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
template <typename>
3+
using Z = int;
4+
5+
template <typename T, typename U = int>
6+
struct Thing {
7+
int x;
8+
};
9+
10+
template <typename T>
11+
struct Thing<T, Z<typename T::Undefined>> {
12+
int y;
13+
};
14+
15+
// Note that float::Undefined is an error, so this should match the primary
16+
// template, not the partial specialization.
17+
Thing<float> thing_float;
18+
19+
void f() {
20+
// If we incorrectly matched the partial specialization, this write to x would
21+
// be an error.
22+
thing_float.x = 1;
23+
}
24+
25+
// Now, a type that actually does define Undefined
26+
struct S {
27+
using Undefined = int;
28+
};
29+
30+
// S::Undefined is okay, so this should match the partial specialization.
31+
Thing<S> thing_s;
32+
33+
void g() {
34+
// If we incorrectly matched the primary template, this write to y would be an
35+
// error.
36+
thing_s.y = 1;
37+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test.cpp:17:14:17:24 | thing_float | test.cpp:6:8:6:12 | Thing<float, int> | test.cpp:7:7:7:7 | x |
2+
| test.cpp:31:10:31:16 | thing_s | test.cpp:11:8:11:41 | Thing<S, int> | test.cpp:12:7:12:7 | y |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import cpp
2+
3+
from Variable v, Class c
4+
where c = v.getType()
5+
and v.getFile().getBaseName() = "test.cpp"
6+
select v, c, c.getAMemberVariable()

0 commit comments

Comments
 (0)