Skip to content

Commit 58fa16a

Browse files
Detect compilations with no warnings when '-w' flag is present.
Gcc may be compiled to auto include warnings such as -Wformat. However, passing in `-w` will suppress the enabled format warnings. The previous query would not raise an issue, as it saw the `-Wformat` flag etc, even though if `-w` was present, causing gcc to run with no warnings enabled.
1 parent fb43031 commit 58fa16a

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

cpp/autosar/src/rules/A1-1-2/CompilerWarningLevelNotInCompliance.ql

+10-6
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,19 @@
1818
import cpp
1919
import codingstandards.cpp.autosar
2020

21-
predicate hasResponseFileArgument(Compilation c) { c.getAnArgument().matches("@%") }
21+
class CompilationWithNoWarnings extends Compilation {
22+
CompilationWithNoWarnings() {
23+
getAnArgument() = "-w"
24+
or not getAnArgument().regexpMatch("-W[\\w=-]+")
25+
}
26+
}
2227

23-
predicate hasWarningOption(Compilation c) { c.getAnArgument().regexpMatch("-W[\\w=-]+") }
28+
predicate hasResponseFileArgument(Compilation c) { c.getAnArgument().matches("@%") }
2429

2530
from File f
2631
where
2732
not isExcluded(f, ToolchainPackage::compilerWarningLevelNotInComplianceQuery()) and
28-
exists(Compilation c | f = c.getAFileCompiled() |
29-
not hasResponseFileArgument(c) and
30-
not hasWarningOption(c)
33+
exists(CompilationWithNoWarnings c | f = c.getAFileCompiled() |
34+
not hasResponseFileArgument(c)
3135
)
32-
select f, "No warning-level options were used in the compilation of '" + f.getBaseName() + "'."
36+
select f, "No warning-level options were used in the compilation of '" + f.getBaseName() + "'."

0 commit comments

Comments
 (0)