Consider the following test case which is processed by AStyle 3.1 as follows:
./astyle --options=none --pad-oper < test.cpp
class Foo
{
public:
Foo();
private:
int** i_;
float** f_;
};
Foo::Foo()
: i_(new int*[100])
, f_(new float*[100])
{
}
The constructor definition is then formatted as follows:
Foo::Foo()
: i_(new int*[100])
, f_(new float * [100])
{
}
As we see, the float pointer is considered to be a multiplication operator, not a pointer, and we get unwanted space before/after. The int pointer is formatted correctly.
I have tried a few other types, and it seems as if only int pointer is formatted correctly
The bug seems to apply to the class initializer list only. For instance, the following is left unchanged (the correct behaviour):
Foo::Foo()
{
i_ = new int*[100];
f_ = new float*[100];
}
Nearly all types (exept char, int, void, xxx_t, INT and VOID) are affected by this, even self defined types.
The attached patch (#501.patch) is probably the most minimally invasive change that would fix all of them. But on the other side will damage "--align-pointer" for self defined types only.
It's not absolutely clear for me what function isPointerOrReferenceVariable should really do, so maybe attached patch (#501_more_universal.patch) would do a better job, especially since function isNumericVariable is doint nearly the same thing. Here "--pad-oper" doesn't work for self defined types but "--align-pointer" works fine instead. So I personally would prefer that fix!