diff --git a/addons/misra.py b/addons/misra.py index f157b7c33..bb8274368 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -1640,13 +1640,21 @@ class MisraChecker: def misra_12_3(self, data): for token in data.tokenlist: - if token.scope.type in ('Class', 'Struct'): - continue if token.str == ';' and (token.isSplittedVarDecl is True): self.reportError(token, 12, 3) if token.str == ',' and token.astParent and token.astParent.str == ';': self.reportError(token, 12, 3) if token.str == ',' and token.astParent is None: + if token.scope.type in ('Class', 'Struct'): + # Is this initlist.. + tok = token + while tok and tok.str == ',': + tok = tok.next + if tok and tok.next and tok.isName and tok.next.str == '(': + tok = tok.next.link.next + if tok.str == '{': + # This comma is used in initlist, do not warn + continue prev = token.previous while prev: if prev.str == ';': diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index 55b9d4620..d7f6136b9 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -393,14 +393,14 @@ enum misra_12_3_e1 { M123A1, M123B1, M123C1 }; enum misra_12_3_e2 { M123A2 = 3, M123B2 = 4, M123C2 }; typedef enum misra_12_3_e3 { M123A3 , M123B3, M123C3 } misra_12_3_e3_t; typedef enum { M123A4 , M123B4, M123C4 } misra_12_3_e4_t; -struct misra_12_3_s1 { int a; int b; int c, d; }; +struct misra_12_3_s1 { int a; int b; int c, d; }; // 12.3 static struct misra_12_3_s1 misra_12_3_s1_inst = { 3, 4, 5, 6, // no warning }; -typedef struct misra_12_3_s2 { int a; int b; int c, d; } misra_12_3_s2_t; -typedef struct { int a; int b; int c, d; } misra_12_3_s3_t; +typedef struct misra_12_3_s2 { int a; int b; int c, d; } misra_12_3_s2_t; // 12.3 +typedef struct { int a; int b; int c, d; } misra_12_3_s3_t; // 12.3 void misra_12_3_fn1(int, int); static int misra_12_3_v5, misra_12_4_v6; // 12.3 void misra_12_3_fn2(int a, int b) // 2.7 { int d, e; } // 12.3