-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathLocalFunctionDeclaration.ql
More file actions
32 lines (27 loc) · 1.11 KB
/
LocalFunctionDeclaration.ql
File metadata and controls
32 lines (27 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* @id cpp/cert/local-function-declaration
* @name DCL53-CPP: Declare functions in the global namespace or other namespace
* @description Declaration of functions inside a function requires the use of ambiguous syntax that
* could lead to unintended behavior.
* @kind problem
* @precision very-high
* @problem.severity warning
* @tags external/cert/id/dcl53-cpp
* correctness
* external/cert/obligation/rule
*/
import cpp
import codingstandards.cpp.cert
class LocalUserFunctionDeclarationEntry extends FunctionDeclarationEntry {
DeclStmt ds;
LocalUserFunctionDeclarationEntry() { ds.getADeclarationEntry() = this }
Function getEnclosingFunction() { result = ds.getEnclosingFunction() }
}
from LocalUserFunctionDeclarationEntry de, Function scope
where
not isExcluded(de, ScopePackage::localFunctionDeclarationQuery()) and
scope = de.getEnclosingFunction() and
// Exclude definitions because they don't use ambiguous syntax.
not de.isDefinition() and
not de.isInMacroExpansion()
select de, "Function $@ declares local function " + de.getName() + ".", scope, scope.getName()