Skip to content

Commit 204e75d

Browse files
authored
Fixed #11909 (misra addon: rule 1.2 detect some gcc language extensions) (#5390)
1 parent c3136db commit 204e75d

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

addons/misra.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,15 @@ def _save_ctu_summary_usage(self, dumpfile, cfg):
14571457
cppcheckdata.reportSummary(dumpfile, 'MisraUsage', names)
14581458

14591459

1460+
def misra_1_2(self, cfg):
1461+
# gcc language extensions: https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html
1462+
for token in cfg.tokenlist:
1463+
if simpleMatch(token, '? :'):
1464+
self.reportError(token, 1, 2)
1465+
elif simpleMatch(token, '( {') and simpleMatch(token.next.link.previous, '; } )'):
1466+
self.reportError(token, 1, 2)
1467+
1468+
14601469
def misra_1_4(self, cfg):
14611470
for token in cfg.tokenlist:
14621471
if token.str in ('_Atomic', '_Noreturn', '_Generic', '_Thread_local', '_Alignas', '_Alignof'):
@@ -4311,6 +4320,7 @@ def fillVerifyExpected(verify_expected, tok):
43114320
if not self.settings.quiet:
43124321
self.printStatus('Checking %s, config %s...' % (dumpfile, cfg.name))
43134322

4323+
self.executeCheck(102, self.misra_1_2, cfg)
43144324
if not path_premium_addon:
43154325
self.executeCheck(104, self.misra_1_4, cfg)
43164326
self.executeCheck(202, self.misra_2_2, cfg)

addons/test/misra/misra-test.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ typedef unsigned int u32;
5858
typedef signed int s32;
5959
typedef unsigned long long u64;
6060

61+
static void misra_1_2(void)
62+
{
63+
(void)(condition ? : 0); // 1.2
64+
a = 1 + ({if (!expr) {code;} 1;}); // 1.2
65+
}
66+
6167
static _Atomic int misra_1_4_var; // 1.4
6268
static _Noreturn void misra_1_4_func(void) // 1.4
6369
{

0 commit comments

Comments
 (0)