Skip to content

Commit 809d97d

Browse files
author
Matthew Gretton-Dann
committed
C++: Print print nontype template params
1 parent f1c3ce0 commit 809d97d

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ private string getParameterTypeString(Type parameterType) {
3535
else result = parameterType.(DumpType).getTypeIdentityString()
3636
}
3737

38+
private string getTemplateArgumentString(Declaration d, int i) {
39+
if exists(d.getTemplateArgumentValue(i))
40+
then
41+
result = d.getTemplateArgument(i).(DumpType).getTypeIdentityString() + " " + d.getTemplateArgumentValue(i)
42+
else
43+
result = d.getTemplateArgument(i).(DumpType).getTypeIdentityString()
44+
}
45+
3846
/**
3947
* A `Declaration` extended to add methods for generating strings useful only for dumps and debugging.
4048
*/
@@ -56,7 +64,7 @@ abstract private class DumpDeclaration extends Declaration {
5664
strictconcat(int i |
5765
exists(this.getTemplateArgument(i))
5866
|
59-
this.getTemplateArgument(i).(DumpType).getTypeIdentityString(), ", " order by i
67+
getTemplateArgumentString(this, i), ", " order by i
6068
) + ">"
6169
else result = ""
6270
}

cpp/ql/test/library-tests/ir/ir/PrintAST.expected

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ bad_asts.cpp:
6767
# 5| params:
6868
#-----| 0: [Parameter] p#0
6969
#-----| Type = [RValueReferenceType] S &&
70-
# 9| [FunctionTemplateInstantiation,MemberFunction] int Bad::S::MemberFunction<int>(int)
70+
# 9| [FunctionTemplateInstantiation,MemberFunction] int Bad::S::MemberFunction<int 6>(int)
7171
# 9| params:
7272
# 9| 0: [Parameter] y
7373
# 9| Type = [IntType] int
@@ -92,7 +92,7 @@ bad_asts.cpp:
9292
# 10| 1: [VariableAccess] y
9393
# 10| Type = [IntType] int
9494
# 10| ValueCategory = prvalue(load)
95-
# 9| [MemberFunction,TemplateFunction] int Bad::S::MemberFunction<int>(int)
95+
# 9| [MemberFunction,TemplateFunction] int Bad::S::MemberFunction<int t>(int)
9696
# 9| params:
9797
# 9| 0: [Parameter] y
9898
# 9| Type = [IntType] int
@@ -104,8 +104,9 @@ bad_asts.cpp:
104104
# 10| 0: [AddExpr] ... + ...
105105
# 10| Type = [IntType] int
106106
# 10| ValueCategory = prvalue
107-
# 10| 0: [Literal] Unknown literal
107+
# 10| 0: [Literal] t
108108
# 10| Type = [IntType] int
109+
# 10| Value = [Literal] t
109110
# 10| ValueCategory = prvalue
110111
# 10| 1: [PointerFieldAccess] x
111112
# 10| Type = [IntType] int

cpp/ql/test/library-tests/ir/ir/raw_ir.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
bad_asts.cpp:
2-
# 9| int Bad::S::MemberFunction<int>(int)
2+
# 9| int Bad::S::MemberFunction<int 6>(int)
33
# 9| Block 0
44
# 9| v0_0(void) = EnterFunction :
55
# 9| mu0_1(unknown) = AliasedDefinition :

0 commit comments

Comments
 (0)