Skip to content

Commit d261244

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

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,26 @@ 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`.
189+
* Observe that, as `T` is not instantiated, `m` is represented by a `Literal` and not a `Declaration`.
190+
*/
191+
Literal getReferencedMember() { usings(underlyingElement(this), unresolveElement(result), _, _) }
192+
193+
override string toString() {
194+
result = "using " + this.getDeclaration().getDescription() or
195+
result = "using " + this.getReferencedMember()
196+
}
178197
}
179198

180199
/**

0 commit comments

Comments
 (0)