Skip to content

Commit 5f54a86

Browse files
committed
C++: Small cleanup. This has no effect on semantics.
1 parent 7723324 commit 5f54a86

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

cpp/ql/lib/semmle/code/cpp/dataflow/ExternalFlow.qll

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,12 @@ private predicate isClassConstructedFrom(Class c, Class templateClass) {
276276
not c.isConstructedFrom(_) and c = templateClass
277277
}
278278

279+
/** Gets the fully templated version of `f`. */
280+
private Class getFullyTemplatedClass(Class c) {
281+
not c.isFromUninstantiatedTemplate(_) and
282+
isClassConstructedFrom(c, result)
283+
}
284+
279285
/**
280286
* Holds if `f` is an instantiation of a function template `templateFunc`, or
281287
* holds with `f = templateFunc` if `f` is not an instantiation of any function
@@ -312,7 +318,7 @@ private string withConst(string s, Type t) {
312318
if t.isConst() then result = "const " + s else result = s
313319
}
314320

315-
/** Prefixes `volatile` to `s` if `t` is const, or returns `s` otherwise. */
321+
/** Prefixes `volatile` to `s` if `t` is volatile, or returns `s` otherwise. */
316322
bindingset[s, t]
317323
private string withVolatile(string s, Type t) {
318324
if t.isVolatile() then result = "volatile " + s else result = s
@@ -490,7 +496,7 @@ pragma[nomagic]
490496
private string getTypeNameWithoutClassTemplates(Function f, int n, int remaining) {
491497
// If there is a declaring type then we start by expanding the function templates
492498
exists(Class template |
493-
isClassConstructedFrom(f.getDeclaringType(), template) and
499+
template = getFullyTemplatedClass(f.getDeclaringType()) and
494500
remaining = getNumberOfSupportedClassTemplateArguments(template) and
495501
result = getTypeNameWithoutFunctionTemplates(f, n, 0)
496502
)
@@ -502,7 +508,7 @@ private string getTypeNameWithoutClassTemplates(Function f, int n, int remaining
502508
or
503509
exists(string mid, TypeTemplateParameter tp, Class template |
504510
mid = getTypeNameWithoutClassTemplates(f, n, remaining + 1) and
505-
isClassConstructedFrom(f.getDeclaringType(), template) and
511+
template = getFullyTemplatedClass(f.getDeclaringType()) and
506512
tp = getSupportedClassTemplateArgument(template, remaining)
507513
|
508514
result = mid.replaceAll(tp.getName(), "class:" + remaining.toString())

0 commit comments

Comments
 (0)