Skip to content

Commit 511d7c9

Browse files
committed
C++: Improve solution for UsingDeclarationEntry.
1 parent 3d43160 commit 511d7c9

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

cpp/ql/src/semmle/code/cpp/Declaration.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ class Declaration extends Locatable, @declaration {
9898
this.hasQualifiedName(namespaceQualifier, "", baseName)
9999
}
100100

101-
override string toString() { result = this.getName() }
101+
/**
102+
* Gets a description of this `Declaration` for display purposes.
103+
*/
104+
string getDescription() { result = this.getName() }
105+
106+
final override string toString() { result = this.getDescription() }
102107

103108
/**
104109
* Gets the name of this declaration.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class UsingDeclarationEntry extends UsingEntry {
153153
*/
154154
Declaration getDeclaration() { usings(underlyingElement(this), unresolveElement(result), _) }
155155

156-
override string toString() { result = "using declaration" }
156+
override string toString() { result = "using " + this.getDeclaration().getDescription() }
157157
}
158158

159159
/**

cpp/ql/src/semmle/code/cpp/exprs/Lambda.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class Closure extends Class {
8686
result.getName() = "operator()"
8787
}
8888

89-
override string toString() { result = "decltype([...](...){...})" }
89+
override string getDescription() { result = "decltype([...](...){...})" }
9090
}
9191

9292
/**
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
| templates.cpp:9:5:9:14 | using declaration | UsingDeclarationEntry, enclosingElement:std |
2-
| usings.cpp:8:1:8:11 | using declaration | UsingDeclarationEntry, enclosingElement:(global namespace) |
1+
| templates.cpp:9:5:9:14 | using c | UsingDeclarationEntry, enclosingElement:std |
2+
| usings.cpp:8:1:8:11 | using nf | UsingDeclarationEntry, enclosingElement:(global namespace) |
33
| usings.cpp:9:1:9:17 | using namespace N | UsingDirectiveEntry, enclosingElement:(global namespace) |
4-
| usings.cpp:18:3:18:13 | using declaration | UsingDeclarationEntry, enclosingElement:D |
5-
| usings.cpp:21:5:21:14 | using declaration | UsingDeclarationEntry, enclosingElement:{ ... } |
6-
| usings.cpp:34:3:34:20 | using declaration | UsingDeclarationEntry, enclosingElement:TD |
7-
| usings.cpp:42:5:42:22 | using declaration | UsingDeclarationEntry, enclosingElement:nsbar |
4+
| usings.cpp:18:3:18:13 | using bf | UsingDeclarationEntry, enclosingElement:D |
5+
| usings.cpp:21:5:21:14 | using gf | UsingDeclarationEntry, enclosingElement:{ ... } |
6+
| usings.cpp:34:3:34:20 | using tbf | UsingDeclarationEntry, enclosingElement:TD |
7+
| usings.cpp:42:5:42:22 | using foo | UsingDeclarationEntry, enclosingElement:nsbar |

0 commit comments

Comments
 (0)