C++: test for resolving specialisations dependent on template aliases

This commit is contained in:
Nick Rolfe
2018-08-09 16:58:48 +01:00
parent f904aed016
commit 5bef9f7118
3 changed files with 45 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
template <typename>
using Z = int;
template <typename T, typename U = int>
struct Thing {
int x;
};
template <typename T>
struct Thing<T, Z<typename T::Undefined>> {
int y;
};
// Note that float::Undefined is an error, so this should match the primary
// template, not the partial specialization.
Thing<float> thing_float;
void f() {
// If we incorrectly matched the partial specialization, this write to x would
// be an error.
thing_float.x = 1;
}
// Now, a type that actually does define Undefined
struct S {
using Undefined = int;
};
// S::Undefined is okay, so this should match the partial specialization.
Thing<S> thing_s;
void g() {
// If we incorrectly matched the primary template, this write to y would be an
// error.
thing_s.y = 1;
}

View File

@@ -0,0 +1,2 @@
| test.cpp:17:14:17:24 | thing_float | test.cpp:6:8:6:12 | Thing<float, int> | test.cpp:7:7:7:7 | x |
| test.cpp:31:10:31:16 | thing_s | test.cpp:11:8:11:41 | Thing<S, int> | test.cpp:12:7:12:7 | y |

View File

@@ -0,0 +1,6 @@
import cpp
from Variable v, Class c
where c = v.getType()
and v.getFile().getBaseName() = "test.cpp"
select v, c, c.getAMemberVariable()