misra: Fix false positives for rule 7.3 (#3236)

Fix false positives for the identifiers that contain 'ul' in their names.

Reported on the forum: https://sourceforge.net/p/cppcheck/discussion/general/thread/c326538221/
This commit is contained in:
Georgiy Komarov 2021-04-27 20:42:34 +03:00 committed by GitHub
parent bd97b8eb8a
commit e1bfd369db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -1417,7 +1417,7 @@ class MisraChecker:
reportErrorIfMissingSuffix(parameterDefinition.nameToken, usedParameter)
def misra_7_3(self, rawTokens):
compiled = re.compile(r'^[0-9.uU]+l')
compiled = re.compile(r'^[0-9.]+[Uu]*l+[Uu]*$')
for tok in rawTokens:
if compiled.match(tok.str):
self.reportError(tok, 7, 3)

View File

@ -254,13 +254,25 @@ void misra_7_2(void) {
misra_7_2_call_va_test(1, 2, 3);
}
// The addon should not generate false positives for the identifiers.
struct misra_7_3_s
{
uint32_t ul_clka;
uint32_t test123l;
};
void misra_7_3(void) {
long misra_7_3_a = 0l; //7.3
long misra_7_3_b = 0lU; //7.3
long long misra_7_3_c = 0Ull; //7.3
long long misra_7_3_d = 0ll; //7.3
long double misra_7_3_e = 7.3l; //7.3
}
struct misra_7_3_s misra_7_3_f =
{
.ul_clka = 19U,
.test123l = 23U
};
}
typedef const char* MISRA_7_4_CHAR_CONST;
MISRA_7_4_CHAR_CONST misra_7_4_return_const_type_def (void) { return "return_typedef_const"; }