Fixed #8657 (false postive: MISRA rule 15.7)

This commit is contained in:
Daniel Marjamäki 2018-10-01 20:16:48 +02:00
parent 1fe1ec09a8
commit 90a2a46959
2 changed files with 24 additions and 6 deletions

View File

@ -1326,15 +1326,17 @@ class MisraChecker:
def misra_15_7(self, data):
for token in data.tokenlist:
if not simpleMatch(token, '}'):
for scope in data.scopes:
if scope.type != 'Else':
continue
if not token.scope.type == 'If':
if not simpleMatch(scope.bodyStart, '{ if ('):
continue
if not token.scope.nestedIn.type == 'Else':
tok = scope.bodyStart.next.next.link
if not simpleMatch(tok, ') {'):
continue
if not token.next.str == 'else':
self.reportError(token, 15, 7)
tok = tok.next.link
if not simpleMatch(tok, '} else'):
self.reportError(tok, 15, 7)
# TODO add 16.1 rule

View File

@ -353,9 +353,25 @@ void misra_15_6() {
}
void misra_15_7() {
uint32_t var = 0;
uint32_t var2 = 0;
if (x!=0){} // no-warning
if (x!=0){} else if(x==1){} // 15.7
if (x!=0){} else if(x==1){}else{;} // no-warning
if (x!=0)
{
}
else
{
var = 5u;
if (var != 5u)
{
var2 = 10u;
} // no-warning
}
}
void misra_16_2() {