Menu

#339 --add-brackets misses nested single statement control structures

open
nobody
None
2015-09-11
2015-02-01
legalize
No
void identity(MATRIX m)
{
    for (int i = 0 ; i < CMAX; i++)
        for (int j = 0; j < RMAX; j++)
            if (i == j)
                m[j][i] = 1.0;
            else
                m[j][i] = 0.0;
}

becomes

void identity(MATRIX m)
{
    for (int i = 0 ; i < CMAX; i++)
        for (int j = 0; j < RMAX; j++)
            if (i == j)
            {
                m[j][i] = 1.0;
            }
            else
            {
                m[j][i] = 0.0;
            }
}

but it should have become

void identity(MATRIX m)
{
    for (int i = 0 ; i < CMAX; i++)
    {
        for (int j = 0; j < RMAX; j++)
        {
            if (i == j)
            {
                m[j][i] = 1.0;
            }
            else
            {
                m[j][i] = 0.0;
            }
        }
    }
}

Discussion

  • legalize

    legalize - 2015-02-01

    astyle --version
    Artistic Style Version 2.03

     
  • Anonymous

    Anonymous - 2015-03-18

    This bug is also in Artistic Style Version 2.05.1.

     
  • Anonymous

    Anonymous - 2015-03-18

    Upon some further searching, this looks like a duplicate of 320.

     
  • Kaylx

    Kaylx - 2015-09-11

    This has been annoying me for some time so i decided to fix it.
    I've attached the patch files.
    Feel free to modify / test till you heart's content.

    UPDATE: I thought i had fixed it, turns out i didn't.

     

    Last edit: Kaylx 2015-09-11
  • Jim Pattee

    Jim Pattee - 2015-09-11

    When making changes like this it is usually best to use the AStyleTest program.
    It is probably going to require making the addBracketsToStatement() method recursive.

     
  • Kaylx

    Kaylx - 2015-09-11

    I didn't know such a thing existed. :)
    I just modified the 2.05.1 Windows download code.

    I see AStyleTest is in the code repo.
    I will use it next time.
    Thanks for pointing it out.

     

Log in to post a comment.