Skip to content

Commit e31f722

Browse files
committed
C++: Add support for getting referenced literals in using declarations
1 parent 7d7ea72 commit e31f722

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,27 @@ class UsingDeclarationEntry extends UsingEntry {
174174
*/
175175
Declaration getDeclaration() { usings(underlyingElement(this), unresolveElement(result), _, _) }
176176

177-
override string toString() { result = "using " + this.getDeclaration().getDescription() }
177+
/**
178+
* Gets the member that is referenced by this using declaration, where the member depends on a
179+
* type template parameter.
180+
*
181+
* For example:
182+
* ```
183+
* template <typename T>
184+
* class A {
185+
* using T::m;
186+
* };
187+
* ```
188+
* Here, `getReferencedMember()` yields the member `m` of `T`. Observe that,
189+
* as `T` is not instantiated, `m` is represented by a `Literal` and not
190+
* a `Declaration`.
191+
*/
192+
Literal getReferencedMember() { usings(underlyingElement(this), unresolveElement(result), _, _) }
193+
194+
override string toString() {
195+
result = "using " + this.getDeclaration().getDescription() or
196+
result = "using " + this.getReferencedMember()
197+
}
178198
}
179199

180200
/**

0 commit comments

Comments
 (0)