mirror of
https://github.com/github/codeql.git
synced 2025-12-21 19:26:31 +01:00
C++: Unknown template literals are constant
This commit is contained in:
@@ -131,6 +131,8 @@ class Expr extends StmtParent, @expr {
|
||||
valuebind(_, underlyingElement(this))
|
||||
or
|
||||
addressConstantExpression(this)
|
||||
or
|
||||
constantTemplateLiteral(this)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1119,3 +1121,17 @@ private predicate isStandardPlacementNewAllocator(Function operatorNew) {
|
||||
|
||||
// Pulled out for performance. See QL-796.
|
||||
private predicate hasNoConversions(Expr e) { not e.hasConversion() }
|
||||
|
||||
/**
|
||||
* Holds if `e` is a literal of unknown value in a template, or a cast thereof.
|
||||
* We assume that such literals are constant.
|
||||
*/
|
||||
private predicate constantTemplateLiteral(Expr e) {
|
||||
// Unknown literals in uninstantiated templates could be enum constant
|
||||
// accesses or pointer-to-member literals.
|
||||
e instanceof Literal and
|
||||
e.isFromUninstantiatedTemplate(_) and
|
||||
not exists(e.getValue())
|
||||
or
|
||||
constantTemplateLiteral(e.(Cast).getExpr())
|
||||
}
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
| staticlocals__staticlocals_f2 | file://:0:0:0:0 | call to C | staticlocals.cpp:30:1:30:1 | return ... | Standard edge, only from QL | |
|
||||
| staticlocals__staticlocals_f2 | file://:0:0:0:0 | initializer for c | file://:0:0:0:0 | call to C | Standard edge, only from QL | |
|
||||
| staticlocals__staticlocals_f2 | staticlocals.cpp:29:5:29:17 | declaration | file://:0:0:0:0 | initializer for c | Standard edge, only from QL | |
|
||||
| staticlocals__staticlocals_f3 | staticlocals.cpp:39:3:39:34 | declaration | staticlocals.cpp:39:18:39:33 | initializer for i | Standard edge, only from QL | uninstantiated |
|
||||
| staticlocals__staticlocals_f3 | staticlocals.cpp:39:18:39:33 | Unknown literal | staticlocals.cpp:40:1:40:1 | return ... | Standard edge, only from QL | uninstantiated |
|
||||
| staticlocals__staticlocals_f3 | staticlocals.cpp:39:18:39:33 | initializer for i | staticlocals.cpp:39:18:39:33 | Unknown literal | Standard edge, only from QL | uninstantiated |
|
||||
|
||||
Reference in New Issue
Block a user