misra; implement rule 20.9

This commit is contained in:
Daniel Marjamäki 2021-07-22 12:08:51 +02:00
parent 74ab8f1a48
commit 3ba4696f4f
2 changed files with 20 additions and 3 deletions

View File

@ -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)

View File

@ -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