Skip to content

Commit bc53286

Browse files
authored
Merge pull request #550 from kraiouchkine/a16-2-2-fix-453
A16-2-2: Exclude reporting of nested redundant includes
2 parents 14a0431 + cfcbf23 commit bc53286

File tree

6 files changed

+26
-4
lines changed

6 files changed

+26
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `A16-2-2` - `UnusedIncludeDirectives.ql`:
2+
- Address FP reported in #453. Exclude reporting of redundant include directives indirectly included by included files.

cpp/autosar/src/rules/A16-2-2/UnusedIncludeDirectives.ql

+12-3
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,19 @@ private predicate firstReliableProvide(File f, File g, int line) {
223223

224224
cached
225225
predicate mayProvideFirst(IncludeDepends i, File g) {
226-
// i may provide g and does not come after a reliable include of g.
226+
// i may provide g
227227
i.provides(g) and
228-
not exists(int line | firstReliableProvide(i.getFile(), g, line) |
229-
line < i.getLocation().getStartLine()
228+
(
229+
// and does not come after a reliable include of g.
230+
not exists(int line | firstReliableProvide(i.getFile(), g, line) |
231+
line < i.getLocation().getStartLine()
232+
)
233+
or
234+
// or it comes after a reliable include of g, and although redundant,
235+
// is not necessarily an issue e.g. in the case of libraries with
236+
// public header forwards to an internal header.
237+
// therefore, hold for transitive includes as well to exclude those results.
238+
not i.getIncludedFile() = g
230239
)
231240
}
232241

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void f();
+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
void f();
1+
#include "z.h"
2+
3+
void g() { f(); }
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "test.hpp" // COMPLIANT
2+
#include "z.h" // COMPLIANT
3+
4+
void test() {
5+
f();
6+
g();
7+
}

cpp/autosar/test/rules/A16-2-2/z.h

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "internal.h"

0 commit comments

Comments
 (0)