Skip to content

Commit 5ae8fe5

Browse files
committed
C++: Correctly identify orphaned variables as static
1 parent 798357f commit 5ae8fe5

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

cpp/ql/lib/semmle/code/cpp/Variable.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,10 @@ class LocalVariable extends LocalScopeVariable, @localvariable {
410410
or
411411
orphaned_variables(underlyingElement(this), unresolveElement(result))
412412
}
413+
414+
override predicate isStatic() {
415+
super.isStatic() or orphaned_variables(underlyingElement(this), _)
416+
}
413417
}
414418

415419
/**

cpp/ql/test/library-tests/variables/variables/variable.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@
3939
| variables.cpp:51:9:51:12 | town | file://:0:0:0:0 | char * | Field | | |
4040
| variables.cpp:52:16:52:22 | country | file://:0:0:0:0 | char * | MemberVariable, StaticStorageDurationVariable | | static |
4141
| variables.cpp:56:14:56:29 | externInFunction | file://:0:0:0:0 | int | GlobalLikeVariable, GlobalVariable, StaticStorageDurationVariable | | |
42-
| variables.cpp:60:10:60:17 | __func__ | file://:0:0:0:0 | const char[9] | LocalVariable, SemanticStackVariable | | |
42+
| variables.cpp:60:10:60:17 | __func__ | file://:0:0:0:0 | const char[9] | GlobalLikeVariable, StaticInitializedStaticLocalVariable | | static |

0 commit comments

Comments
 (0)