diff --git a/addons/misra.py b/addons/misra.py index 28b879807..2b2bea867 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -3215,6 +3215,16 @@ class MisraChecker: if cond.result and cond.result not in (0,1): self.reportError(cond, 20, 8) + def misra_20_9(self, cfg): + for cond in cfg.preprocessor_if_conditions: + if cond.E is None: + continue + for s in cond.E.split(' '): + if (s[0] >= 'A' and s[0] <= 'Z') or (s[0] >= 'a' and s[0] <= 'z'): + if isKeyword(s): + continue + self.reportError(cond, 20, 9) + def misra_20_10(self, data): for directive in data.directives: d = Define(directive) @@ -3892,6 +3902,7 @@ class MisraChecker: self.executeCheck(2005, self.misra_20_5, cfg) self.executeCheck(2007, self.misra_20_7, cfg) self.executeCheck(2008, self.misra_20_8, cfg) + self.executeCheck(2009, self.misra_20_9, cfg) self.executeCheck(2010, self.misra_20_10, cfg) self.executeCheck(2013, self.misra_20_13, cfg) self.executeCheck(2014, self.misra_20_14, cfg) diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index c623b4697..e83208a84 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -1231,11 +1231,11 @@ static void misra_15_6(void) { if (x!=0); // 15.6 else{} -#if A>1 // no-warning +#if A>1 // 20.9 (void)0; #endif -#if A > 0x42 +#if A > 0x42 // 20.9 if (true) { (void)0; } @@ -1559,13 +1559,19 @@ struct { int a; } struct_20_7_s; #define MUL(a ,b ) ( a * b ) // 20.7 #if __LINE__ // 20.8 +#elif 2+5 // 20.8 +#elif 2-2 +#endif + +#if A // 20.9 +#elif B || C // 20.9 #endif #define M_20_10(a) (#a) // 20.10 #else1 // 20.13 -#ifdef A>1 +#ifdef A # define somethingis 5 // no warning # define func_20_13(v) (v) // no warning #else