Fixed #8823 (false positive: MISRA rule 16.3)

This commit is contained in:
Daniel Marjamäki 2019-08-11 19:08:57 +02:00
parent db57769c64
commit 2e9e3ed2f1
2 changed files with 23 additions and 2 deletions

View File

@ -1519,8 +1519,12 @@ class MisraChecker:
state = STATE_OK
elif token.str == '}' and state == STATE_OK:
# is this {} an unconditional block of code?
link = findRawLink(token)
if (link is None) or (link.previous is None) or (link.previous.str not in ':;{}'):
prev = findRawLink(token)
if prev:
prev = prev.previous
while prev and prev.str[:2] in ('//', '/*'):
prev = prev.previous
if (prev is None) or (prev.str not in ':;{}'):
state = STATE_NONE
elif token.str == 'case' or token.str == 'default':
if state != STATE_OK:

View File

@ -441,6 +441,23 @@ void misra_16_3() {
case 12:
default: break;
}
switch (x) {
case 1: // comment 1
{
a = 1;
break;
}
case 2: // comment 2
{
a = 2;
break;
}
default:
{
break;
}
}
}
void misra_16_4() {