forked from github/codeql-coding-standards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsingDeclarationsUsedInHeaderFiles.ql
More file actions
40 lines (35 loc) · 1.31 KB
/
UsingDeclarationsUsedInHeaderFiles.ql
File metadata and controls
40 lines (35 loc) · 1.31 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
33
34
35
36
37
38
39
40
/**
* @id cpp/autosar/using-declarations-used-in-header-files
* @name M7-3-6: Using-directives and using-declarations shall not be used in header files
* @description Using-directives and using-declarations (excluding class scope or function scope
* using-declarations) shall not be used in header files.
* @kind problem
* @precision very-high
* @problem.severity error
* @tags external/autosar/id/m7-3-6
* correctness
* scope/single-translation-unit
* external/autosar/allocated-target/implementation
* external/autosar/enforcement/automated
* external/autosar/obligation/required
*/
import cpp
import codingstandards.cpp.autosar
predicate isInHeaderFile(UsingEntry u) { u.getFile() instanceof HeaderFile }
predicate isInFunctionScope(UsingEntry u) {
exists(Function f | u.getParentScope().(BlockStmt).getEnclosingFunction() = f)
}
predicate isInClassScope(UsingEntry u) { exists(Class c | u.getEnclosingElement() = c) }
from UsingEntry u
where
not isExcluded(u, BannedSyntaxPackage::usingDeclarationsUsedInHeaderFilesQuery()) and
isInHeaderFile(u) and
(
u instanceof UsingDeclarationEntry
implies
(
not isInFunctionScope(u) and
not isInClassScope(u)
)
)
select u, "Using directive or declaration used in a header file " + u.getFile() + "."