From fc504ed6c3af11ced0ad1baf33d2bda2af4304f9 Mon Sep 17 00:00:00 2001 From: Georgy Komarov Date: Tue, 21 Jul 2020 19:59:11 +0300 Subject: [PATCH] misra.py: Fix false positives on macro expansion This will fix Trac#9634 --- addons/misra.py | 4 +++- addons/test/misra/misra-test.c | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/misra.py b/addons/misra.py index 6e8b1602f..361a15e63 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -2322,7 +2322,9 @@ class MisraChecker: while pos1 >= 0 and exp[pos1] == ' ': pos1 -= 1 - if exp[pos1] not in '([#,.': + if exp[pos1] == '#': + continue + if exp[pos1] not in '([,.': self.reportError(directive, 20, 7) break while pos2 < len(exp) and exp[pos2] == ' ': diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index d3a7a1b52..1e73d37d5 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -1027,6 +1027,10 @@ union misra_19_2 { }; // 19.2 #define M_20_7_3(A) ((A)+A) // 20.7 #define M_20_7_4(A) x##A // 20.10 this test was written to see there are not FPs #define M_20_7_5(A,B) f(A, B) // no warning +#define M_20_7_6(x) a ## x = ( x ) // 20.10 +#define M_20_7_7(x) a = # x // 20.10 +#define M_20_7_8(x, fn) a = fn ( # x ) // 20.7 20.10 +#define M_20_7_9(x, fn) a = (fn) ( # x ) // 20.10 // Compliant: M is a structure member name, not an expression struct { int a; } struct_20_7_s;