mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
C++: test for resolving specialisations dependent on template aliases
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
@@ -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 |
|
||||||
@@ -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()
|
||||||
Reference in New Issue
Block a user