Skip to content

Commit 473ca76

Browse files
committed
C++: Add support for getting referenced literals in using declarations
1 parent c695f4d commit 473ca76

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

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+
* Returns the member referenced by this using declaration when it refers
179+
* to a member of a template type parameter.
180+
*
181+
* For example:
182+
* ```
183+
* template <typename T>
184+
* class A {
185+
* using T::foo; // `foo` is the member referenced by this using declaration
186+
* };
187+
* ```
188+
* `getReferencedMember()` returns the member `foo` declared within the
189+
* template type parameter `T`.
190+
*/
191+
Element 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)