Misra explicitly allows spaces between # and the preprocessing tokens (#1781)

* Misra explicitly allows spaces between # and the preprocessing tokens

* Added tests illustrating need for changing preprocessor checking
This commit is contained in:
eivindt 2019-04-08 18:26:17 +02:00 committed by Daniel Marjamäki
parent 253986bc31
commit ff1114e3c7
2 changed files with 14 additions and 5 deletions

View File

@ -1609,13 +1609,14 @@ class MisraChecker:
def misra_20_13(self, data):
dir_pattern = re.compile(r'#[ ]*([^ (<]*)')
for directive in data.directives:
dir = directive.str
for sep in ' (<':
if dir.find(sep) > 0:
dir = dir[:dir.find(sep)]
if dir not in ['#define', '#elif', '#else', '#endif', '#error', '#if', '#ifdef', '#ifndef', '#include',
'#pragma', '#undef', '#warning']:
mo = dir_pattern.match(dir)
if mo:
dir = mo.group(1)
if dir not in ['define', 'elif', 'else', 'endif', 'error', 'if', 'ifdef', 'ifndef', 'include',
'pragma', 'undef', 'warning']:
self.reportError(directive, 20, 13)

View File

@ -500,6 +500,14 @@ union misra_19_2 { }; // 19.2
#else1 // 20.13
#ifdef A>1
# define somethingis 5 // no warning
# define func_20_13(v) (v) // no warning
#else
# definesomethingis 6 // 20.13
# def fun_2013(v) () // 20.13
#endif
void misra_21_3() {
p1=malloc(10); // 21.3
p2=calloc(10); // 21.3