Skip to content

Commit 27c6e24

Browse files
committed
C++: Add VariableTemplateInstantiation class
This adds some uniformity, as we already had `FunctionTemplateInstantiation` and `ClassTemplateInstantiation` classes.
1 parent 3e96028 commit 27c6e24

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

cpp/ql/lib/semmle/code/cpp/Variable.qll

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,33 @@ class TemplateVariable extends Variable {
590590
Variable getAnInstantiation() { result.isConstructedFrom(this) }
591591
}
592592

593+
/**
594+
* A variable that is an instantiation of a template. For example
595+
* the instantiation `myTemplateVariable<int>` in the following code:
596+
* ```
597+
* template<class T>
598+
* T myTemplateVariable;
599+
*
600+
* void caller(int i) {
601+
* myTemplateVariable<int> = i;
602+
* }
603+
* ```
604+
*/
605+
class VariableTemplateInstantiation extends Variable {
606+
TemplateVariable tv;
607+
608+
VariableTemplateInstantiation() { tv.getAnInstantiation() = this }
609+
610+
override string getAPrimaryQlClass() { result = "VariableTemplateInstantiation" }
611+
612+
/**
613+
* Gets the variable template from which this instantiation was instantiated.
614+
*
615+
* Example: For `int x<int>`, returns `T x`.
616+
*/
617+
TemplateVariable getTemplate() { result = tv }
618+
}
619+
593620
/**
594621
* A non-static local variable or parameter that is not part of an
595622
* uninstantiated template. Uninstantiated templates are purely syntax, and

0 commit comments

Comments
 (0)