Skip to content

Commit 283991d

Browse files
C++: Handle ProxyClass in getIdentityString()
1 parent 3414c10 commit 283991d

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,13 @@ private class UserDumpType extends DumpType, DumpDeclaration, UserType {
346346
override string getIdentityString() {
347347
exists(string simpleName |
348348
(
349-
if this instanceof Closure then
350-
simpleName = "(" + getSimpleName() + ")"
349+
if this instanceof Closure then (
350+
// Parenthesize the name of the lambda because it's freeform text similar to
351+
// "lambda [] type at line 12, col. 40"
352+
// Use `min(getSimpleName())` to work around an extractor bug where a lambda can have different names
353+
// from different compilation units.
354+
simpleName = "(" + min(getSimpleName()) + ")"
355+
)
351356
else
352357
simpleName = getSimpleName()
353358
) and
@@ -360,6 +365,12 @@ private class UserDumpType extends DumpType, DumpDeclaration, UserType {
360365
}
361366
}
362367

368+
private class DumpProxyClass extends UserDumpType, ProxyClass {
369+
override string getIdentityString() {
370+
result = getName()
371+
}
372+
}
373+
363374
private class DumpVariable extends DumpDeclaration, Variable {
364375
override string getIdentityString() {
365376
exists(DumpType type |

cpp/ql/test/library-tests/identity_string/identity_string.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ void check_var(TVar var, const char* expected);
99

1010
struct S
1111
{
12+
enum NestedEnum
13+
{
14+
Blah,
15+
Bluh
16+
};
17+
1218
int i;
1319
float f;
1420
};
@@ -18,6 +24,13 @@ struct T
1824
bool b;
1925
};
2026

27+
enum E
28+
{
29+
One,
30+
Two,
31+
Three
32+
};
33+
2134
void checks()
2235
{
2336
// Primitive types
@@ -120,6 +133,9 @@ void checks()
120133
check_type<AI>("int[10]");
121134
check_type<CAI>("int const[10]");
122135
check_type<int const[10]>("int const[10]");
136+
137+
check_type<E>("E");
138+
check_type<S::NestedEnum>("S::NestedEnum");
123139
}
124140

125141
int globalVariable;

0 commit comments

Comments
 (0)