Skip to content

Commit 05737af

Browse files
committed
C++: Only support non-type template parameters in tail position.
1 parent faa55f5 commit 05737af

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

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

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -634,21 +634,28 @@ string getParameterTypeWithoutTemplateArguments(Function f, int n, boolean canon
634634
canonical = true
635635
}
636636

637-
/** Gets the `i`'th supported template parameter for `templateFunction`. */
638-
private Locatable getSupportedFunctionTemplateArgument(Function templateFunction, int i) {
637+
/**
638+
* Gets the largest index of a template parameter of `templateFunction` that
639+
* is a type template parameter.
640+
*/
641+
private int getLastTypeTemplateFunctionParameterIndex(Function templateFunction) {
639642
result =
640-
rank[i + 1](int j, TypeTemplateParameter ttp |
641-
ttp = templateFunction.getTemplateArgument(j)
642-
|
643-
ttp order by j
644-
)
643+
max(int index | templateFunction.getTemplateArgument(index) instanceof TypeTemplateParameter)
645644
}
646645

647646
/** Gets the number of supported template parameters for `templateFunction`. */
648647
private int getNumberOfSupportedFunctionTemplateArguments(Function templateFunction) {
649648
result = count(int i | exists(getSupportedFunctionTemplateArgument(templateFunction, i)) | i)
650649
}
651650

651+
/** Gets the `i`'th supported template parameter for `templateFunction`. */
652+
private Locatable getSupportedFunctionTemplateArgument(Function templateFunction, int i) {
653+
result = templateFunction.getTemplateArgument(i) and
654+
// We don't yet support non-type template parameters in the middle of a
655+
// template parameter list
656+
i <= getLastTypeTemplateFunctionParameterIndex(templateFunction)
657+
}
658+
652659
/**
653660
* Normalize the `n`'th parameter of `f` by replacing template names
654661
* with `func:N` (where `N` is the index of the template).
@@ -669,14 +676,21 @@ private string getTypeNameWithoutFunctionTemplates(Function f, int n, int remain
669676
)
670677
}
671678

679+
/**
680+
* Gets the largest index of a template parameter of `templateFunction` that
681+
* is a type template parameter.
682+
*/
683+
private int getLastTypeTemplateClassParameterIndex(Class templateClass) {
684+
result =
685+
max(int index | templateClass.getTemplateArgument(index) instanceof TypeTemplateParameter)
686+
}
687+
672688
/** Gets the `i`'th supported template parameter for `templateClass`. */
673689
private Locatable getSupportedClassTemplateArgument(Class templateClass, int i) {
674-
result =
675-
rank[i + 1](int j, TypeTemplateParameter ttp |
676-
ttp = templateClass.getTemplateArgument(j)
677-
|
678-
ttp order by j
679-
)
690+
result = templateClass.getTemplateArgument(i) and
691+
// We don't yet support non-type template parameters in the middle of a
692+
// template parameter list
693+
i <= getLastTypeTemplateClassParameterIndex(templateClass)
680694
}
681695

682696
/** Gets the number of supported template parameters for `templateClass`. */

0 commit comments

Comments
 (0)