C++ Code Smell: Incorrect Initializer Braces Placement

548 Views Asked by At

I am trying to fix the following code smell within my C++ code generated from Klocwork(KW):

MISRA.INIT.BRACES: Incorrect initializer braces placement

Below is a snippet of the code I am attempting to clean this up on.

    typedef char charString[10];

    enum SomeEnum
    {
        BLAH1_e,
        BLAH2_e,
        BLAH3_e
    };

    struct ParentStruct
    {
        SomeEnum myEnumValue;
        charString myCharStringValue;
    };

    // This is the the part that KW is not happy about
    // KW complaining about initializer bracer placement
    const ParentStruct myParent[3] = 
    {
        {BLAH1_e, "String1"},
        {BLAH2_e, "String2"},
        {BLAH3_e, "String3"}
    }

I've attempted many variations of bracer placement and can't seem to figure out the exact issue with bracer placement I currently have. This doesn't generate any compile errors nor does this have a negative outcome on the code. Maybe it's just KW but just wanted to get some thoughts before I give up completely.

Below is an alternative bracer placement I attempted as well in case someone throws it out as an answer:

    // compiles but KW does not like this as well
    const ParentStruct myParent[3] = 
    {
        {BLAH1_e, {"String1"}},
        {BLAH2_e, {"String2"}},
        {BLAH3_e, {"String3"}}
    }

    
1

There are 1 best solutions below

0
On

Please do run the analysis with the latest version of Klocwork and check if this issue has been reported by Klocwork at your end.

I am using Klocwork 2021.3 and it seems that MISRA.INIT.BRACES checker is not reporting any issue on your code as expected.