From 452c92494ec2225afe66ac283cf41e06e1ffc295 Mon Sep 17 00:00:00 2001 From: Georgiy Komarov Date: Fri, 25 Jun 2021 17:06:29 +0300 Subject: [PATCH] misra: Fix 8.2 false positives (#3306) Type declaration on the next line is not allowed in rule 8.2. But we need to make sure that the files of the checked files are the same. Reported on the forum: https://sourceforge.net/p/cppcheck/discussion/development/thread/801dc07e59/#32c3/e90b/293e/39df/85b3/b821/e0c3 --- addons/misra.py | 4 +++- addons/test/misra/misra-test.c | 4 ++++ addons/test/misra/misra-test.h | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/addons/misra.py b/addons/misra.py index 281d8dec9..600d56c06 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -1512,7 +1512,9 @@ class MisraChecker: self.reportError(typeStartToken, 8, 2) # Type declaration on next line (old style declaration list) is not allowed - if (typeStartToken.linenr > endCall.linenr) or (typeStartToken.column > endCall.column): + if ((typeStartToken.file == endCall.file) and + ((typeStartToken.linenr > endCall.linenr) or + (typeStartToken.column > endCall.column))): self.reportError(typeStartToken, 8, 2) # Check arguments in pointer declarations diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index 7881c488d..5b552e6ec 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -322,6 +322,10 @@ static int misra_8_2_l ( // 8.2 int16_t ( *misra_8_2_p_a ) (); // 8.2 int16_t ( *misra_8_2_p_b ) (void); int16_t ( *misra_8_2_p_c ) (int); +int misra_8_2_no_fp (int a) +{ + return a + 42; +} extern int a811[]; // 8.11 diff --git a/addons/test/misra/misra-test.h b/addons/test/misra/misra-test.h index ed932fcaf..74e49e58b 100644 --- a/addons/test/misra/misra-test.h +++ b/addons/test/misra/misra-test.h @@ -3,4 +3,5 @@ struct misra_h_s { int foo; }; bool test(char *); // 8.2 bool test(char *a); // OK +int misra_8_2_no_fp(int a); #endif // MISRA_TEST_H