diff --git a/cpp/ql/test/library-tests/templates/dependent_template_alias/test.cpp b/cpp/ql/test/library-tests/templates/dependent_template_alias/test.cpp new file mode 100644 index 00000000000..06ff13df9f6 --- /dev/null +++ b/cpp/ql/test/library-tests/templates/dependent_template_alias/test.cpp @@ -0,0 +1,37 @@ + +template +using Z = int; + +template +struct Thing { + int x; +}; + +template +struct Thing> { + int y; +}; + +// Note that float::Undefined is an error, so this should match the primary +// template, not the partial specialization. +Thing 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 thing_s; + +void g() { + // If we incorrectly matched the primary template, this write to y would be an + // error. + thing_s.y = 1; +} diff --git a/cpp/ql/test/library-tests/templates/dependent_template_alias/test.expected b/cpp/ql/test/library-tests/templates/dependent_template_alias/test.expected new file mode 100644 index 00000000000..a1127fad4e3 --- /dev/null +++ b/cpp/ql/test/library-tests/templates/dependent_template_alias/test.expected @@ -0,0 +1,2 @@ +| test.cpp:17:14:17:24 | thing_float | test.cpp:6:8:6:12 | Thing | test.cpp:7:7:7:7 | x | +| test.cpp:31:10:31:16 | thing_s | test.cpp:11:8:11:41 | Thing | test.cpp:12:7:12:7 | y | diff --git a/cpp/ql/test/library-tests/templates/dependent_template_alias/test.ql b/cpp/ql/test/library-tests/templates/dependent_template_alias/test.ql new file mode 100644 index 00000000000..d61a33c822c --- /dev/null +++ b/cpp/ql/test/library-tests/templates/dependent_template_alias/test.ql @@ -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()