Menu ▾ ▴

#421 Array of C++ class elements not aligned properly for constructors with multi-line arguments

closed-fixed
None
2017-04-09
2017-02-10
AmH
No

I downloaded and compiled the 2.06 tarball just today (to check out this problem found on 2.05.1 on Ubuntu 16.04).

The issue is that this properly indented array of ClassName objects:

ClassName table[] =
{
   ClassName(classarg1name, sizeof(some_long_struct_name), 1,
             ClassName::DESTINATION, 60000, "0.0.0.0"),
   ClassName(classarg1name, sizeof(some_long_struct_name), 1,
             ClassName::DESTINATION, 60001),
};

After formatting becomes this:

ClassName table[] =
{
   ClassName(classarg1name, sizeof(some_long_struct_name), 1,
   ClassName::DESTINATION, 60000, "0.0.0.0"),
   ClassName(classarg1name, sizeof(some_long_struct_name), 1,
   ClassName::DESTINATION, 60001),
};

astyle command-line:

--indent=spaces=3 -A1 --pad-header --unpad-paren -p -j -k3 -m0 -M70 -z2 -xC100

astyle version:

Artistic Style Version 2.06

Discussion

  • Jim Pattee

    Jim Pattee - 2017-02-11
    • status: open --> open-fixed
    • assigned_to: Jim Pattee
     
  • Jim Pattee

    Jim Pattee - 2017-02-11

    Fixed.

     
  • AmH

    AmH - 2017-02-13

    Perhaps a separate bug but definitely related. Given the arguments -xC100 and -M70, I expect this:

    ClassName tables[] =
    {
       ClassName(classarg1name, sizeof(some_long_struct_name), 1, ClassName::DESTINATION, 60000, "0.0.0.0"),
       ClassName(classarg1name, sizeof(some_long_struct_name), 1, ClassName::DESTINATION, 60000, "0.0.0.0"),
    };
    

    To be reformatted to this:

    ClassName tables[] =
    {
       ClassName(classarg1name, sizeof(some_long_struct_name), 1, ClassName::DESTINATION, 60000,
                 "0.0.0.0"),
       ClassName(classarg1name, sizeof(some_long_struct_name), 1, ClassName::DESTINATION, 60000,
                 "0.0.0.0"),
    };
    

    This might still be an options related problem though my understanding is that the combination of -xC100 and -M70 should guarantee the correct behavior. Indeed, this is exactly what happens if the above lines are moved just inside a function's opening brace. It appears -xC100 is ignored in the above initializer list context.

     
  • Jim Pattee

    Jim Pattee - 2017-04-09
    • status: open-fixed --> closed-fixed
     

Log in to post a comment.