Skip to content

Commit 4472983

Browse files
committed
C++: Add support for retrieving referenced literals in using declarations
1 parent d6fd327 commit 4472983

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,28 @@ 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 literal referenced by this `using` declaration.
179+
* This is particularly relevant for `using` declarations that involve template instantiations.
180+
*
181+
* For example:
182+
* ```
183+
* template <typename T>
184+
* class A : public T {
185+
* using T::foo; // `foo` is the literal referenced by this using declaration
186+
* };
187+
* ```
188+
*/
189+
Literal getLiteral() { usings(underlyingElement(this), unresolveElement(result), _, _) }
190+
191+
override string toString() {
192+
if exists(this.getDeclaration())
193+
then result = "using " + this.getDeclaration().getQualifiedName()
194+
else
195+
if exists(this.getLiteral())
196+
then result = "using " + this.getLiteral().toString()
197+
else result = "using <unknown>"
198+
}
178199
}
179200

180201
/**

0 commit comments

Comments
 (0)