-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathIncludeOutsideGuard.ql
More file actions
36 lines (33 loc) · 1.25 KB
/
IncludeOutsideGuard.ql
File metadata and controls
36 lines (33 loc) · 1.25 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
/**
* @id cpp/misra/include-outside-guard
* @name RULE-19-2-1: Comments are the only content permitted outside of the scope of an include guard in a header file
* @description Include directives shall be within the scope of an include guard.
* @kind problem
* @precision very-high
* @problem.severity error
* @tags external/misra/id/rule-19-2-1
* scope/single-translation-unit
* maintainability
* correctness
* external/misra/enforcement/decidable
* external/misra/obligation/required
*/
import cpp
import codingstandards.cpp.misra
import semmle.code.cpp.headers.MultipleInclusion
predicate isOutside(CorrectIncludeGuard includeGuard, Location location) {
location.getFile() = includeGuard.getFile() and
(
location.isBefore(includeGuard.getIfndef().getLocation())
or
includeGuard.getEndif().getLocation().isBefore(location)
)
}
from Include include, CorrectIncludeGuard includeGuard, HeaderFile header
where
not isExcluded(include, PreprocessorPackage::includeOutsideGuardQuery()) and
includeGuard.getFile() = header and
header = include.getFile() and
isOutside(includeGuard, include.getLocation())
select include, "Include is outside of its header file's $@.", includeGuard.getIfndef(),
"include guard"