Fixed #11909 (misra addon: rule 1.2 detect some gcc language extensions) (#5390)

This commit is contained in:
Daniel Marjamäki 2023-09-01 16:44:14 +02:00 committed by GitHub
parent c3136dbc2a
commit 204e75dc59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -1457,6 +1457,15 @@ class MisraChecker:
cppcheckdata.reportSummary(dumpfile, 'MisraUsage', names)
def misra_1_2(self, cfg):
# gcc language extensions: https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html
for token in cfg.tokenlist:
if simpleMatch(token, '? :'):
self.reportError(token, 1, 2)
elif simpleMatch(token, '( {') and simpleMatch(token.next.link.previous, '; } )'):
self.reportError(token, 1, 2)
def misra_1_4(self, cfg):
for token in cfg.tokenlist:
if token.str in ('_Atomic', '_Noreturn', '_Generic', '_Thread_local', '_Alignas', '_Alignof'):
@ -4311,6 +4320,7 @@ class MisraChecker:
if not self.settings.quiet:
self.printStatus('Checking %s, config %s...' % (dumpfile, cfg.name))
self.executeCheck(102, self.misra_1_2, cfg)
if not path_premium_addon:
self.executeCheck(104, self.misra_1_4, cfg)
self.executeCheck(202, self.misra_2_2, cfg)

View File

@ -58,6 +58,12 @@ typedef unsigned int u32;
typedef signed int s32;
typedef unsigned long long u64;
static void misra_1_2(void)
{
(void)(condition ? : 0); // 1.2
a = 1 + ({if (!expr) {code;} 1;}); // 1.2
}
static _Atomic int misra_1_4_var; // 1.4
static _Noreturn void misra_1_4_func(void) // 1.4
{