MISRA 15.7 only checks if...else if constructs (#983)

This commit is contained in:
KMilhan 2017-10-26 15:47:53 +09:00 committed by Daniel Marjamäki
parent a38854451f
commit 76c3cef4d6
2 changed files with 8 additions and 4 deletions

View File

@ -193,7 +193,9 @@ void misra_15_6() {
}
void misra_15_7() {
if (x!=0){} // 15.7
if (x!=0){} // no-warning
if (x!=0){} else if(x==1){} // 15.7
if (x!=0){} else if(x==1){}else{;} // no-warning
}
void misra_16_2() {

View File

@ -773,11 +773,13 @@ def misra_15_6(rawTokens):
def misra_15_7(data):
for token in data.tokenlist:
if not simpleMatch(token, 'if ('):
if not simpleMatch(token, '}'):
continue
if not simpleMatch(token.next.link, ') {'):
if not token.scope.type == 'If':
continue
if not simpleMatch(token.next.link.next.link, '} else'):
if not token.scope.nestedIn.type == 'Else':
continue
if not token.next.str == 'else':
reportError(token, 15, 7)
# TODO add 16.1 rule