diff --git a/addons/cppcheckdata.py b/addons/cppcheckdata.py index 8088ddf06..ab4c0cbb6 100644 --- a/addons/cppcheckdata.py +++ b/addons/cppcheckdata.py @@ -236,6 +236,8 @@ class Scope: classEndId = None classEnd = None className = None + nestedInId = None + nestedIn = None type = None def __init__(self, element): diff --git a/addons/misra-test.c b/addons/misra-test.c index a12bdfb53..3be9d005a 100644 --- a/addons/misra-test.c +++ b/addons/misra-test.c @@ -41,3 +41,10 @@ void misra56() { void misra57() { continue; // 57 } + +void misra58() { + while (1) { + if(x) + break; // 58 + } +} diff --git a/addons/misra.py b/addons/misra.py index 07670c168..d4940d9ad 100644 --- a/addons/misra.py +++ b/addons/misra.py @@ -409,7 +409,14 @@ def misra57(data): # 58 The break statement shall not be used, except to terminate the cases of a switch statement # STATUS: TODO def misra58(data): - return + for token in data.tokenlist: + if token.str != "break": + continue + s = token.scope + while s and s.type == 'If': + s = s.nestedIn + if s and s.type in ['While', 'For']: + reportError(token, 'style', '58 The break statement shall not be used, except to terminate the cases of a switch statement') # 59 The statements forming the body of an if, else, else if, .. shall always be enclosed in braces # STATUS: TODO