Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#83 curly brackets not broken for inline functions

closed-fixed
Jim Pattee
7
2015-01-03
2011-03-30
w-peuker
No

I use --style=kr as base for c++ formatting.
Some functions I use to implement inline for performance reasons (sometimes also for documentation).
After running astyle, the readability of nearly all inline constructors is decreased. The following example is made to show the unwished effects:
class Test {
public:
Test(
int a,
int b):
a(a),
b(b)
{
data = calcdata();
}
int calcdata() {
return x+y;
}
private:
int x;
int y;
int data;
}

becomes

class Test
{
public:
Test(
int a,
int b):
a(a),
b(b) {
data = calcdata();
}
int calcdata() {
return x+y;
}

private:
int x;
int y;
int data;
}

The readability issue arises from the misleading similar indentation of parameters, initialiser-list items and statements in the constructor body.
This you'll find trivial to "decode":
int a,
int b):
a(a),
b(b) {
data = calcdata();
...but what about user defined types and names of normal length?

Discussion

  • w-peuker
    w-peuker
    2011-03-30

    original text

     
    Attachments
  • w-peuker
    w-peuker
    2011-03-30

    formatted output

     
    Attachments
  • w-peuker
    w-peuker
    2011-04-05

    The worst on this bug is the imperceptible transition from the initializer list to the body of inline constructors,
    even if I add a line break before "):", because the "{" is inexorable attached :(

     
  • w-peuker
    w-peuker
    2011-05-13

    These examples make the problem more obvious:

    class TestClass
    {
    public:
    TestClass(
    ALongNamed aLongNamed,
    BLongNamed bLongNamed,
    CLongNamed cLongNamed):
    aLongNamed(aLongNamed),
    bLongNamed(bLongNamed),
    cLongNamed(cLongNamed) {
    cLongNamed.setA(aLongNamed);
    cLongNamed.setB(bLongNamed);
    }

    private:
    ALongNameed aLongNamed;
    BLongNameed bLongNamed;
    CLongNameed cLongNamed;

    };

    The problem remains even if the start of the initializer list is broken (by hand):

    class TestClass
    {
    public:
    TestClass(
    ALongNamed aLongNamed,
    BLongNamed bLongNamed,
    CLongNamed cLongNamed
    ):
    aLongNamed(aLongNamed),
    bLongNamed(bLongNamed),
    cLongNamed(cLongNamed) {
    cLongNamed.setA(aLongNamed);
    cLongNamed.setB(bLongNamed);
    }

    private:
    ALongNameed aLongNamed;
    BLongNameed bLongNamed;
    CLongNameed cLongNamed;

    };

     
  • Jim Pattee
    Jim Pattee
    2014-10-16

    • status: open --> open-fixed
    • assigned_to: Jim Pattee
    • Priority: 5 --> 7
     
  • Jim Pattee
    Jim Pattee
    2014-10-16

    This has been fixed.

     
  • Jim Pattee
    Jim Pattee
    2014-11-20

    • Status: open-fixed --> closed-fixed