Skip to content

Commit 39579ef

Browse files
author
Milhan KIM
committed
MISRA 15.7 only checks if...else if constructs
1 parent eb6bf1b commit 39579ef

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

addons/misra-test.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,9 @@ void misra_15_6() {
193193
}
194194

195195
void misra_15_7() {
196-
if (x!=0){} // 15.7
196+
if (x!=0){} // no-warning
197+
if (x!=0){} else if(x==1){} // 15.7
198+
if (x!=0){} else if(x==1){}else{;} // no-warning
197199
}
198200

199201
void misra_16_2() {

addons/misra.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -773,11 +773,13 @@ def misra_15_6(rawTokens):
773773

774774
def misra_15_7(data):
775775
for token in data.tokenlist:
776-
if not simpleMatch(token, 'if ('):
776+
if not simpleMatch(token, '}'):
777777
continue
778-
if not simpleMatch(token.next.link, ') {'):
778+
if not token.scope.type == 'If':
779+
continue
780+
if not token.scope.nestedIn.type == 'Else':
779781
continue
780-
if not simpleMatch(token.next.link.next.link, '} else'):
782+
if not token.next.str == 'else':
781783
reportError(token, 15, 7)
782784

783785
# TODO add 16.1 rule

0 commit comments

Comments
 (0)