This is a very specific case. Consider the following piece of test C++ code I wrote:
namespace test { struct __attribute__((aligned(16))) TestClass { int test; TestClass() : test(0) {}; TestClass(int i) : test(i) {}; void AddFour(); }; void TestClass::AddFour() { test += 4; } } // namespace test
Running astyle on a file containing such code breaks structure formatting - everything below int test; has its indentations removed. Used options:
style=allman max-code-length=100 attach-namespaces indent=spaces=4 convert-tabs indent-switches pad-oper pad-header align-pointer=type align-reference=type break-after-logical indent-preproc-define
As I explored the issue, there are multiple conditions that have to be met in order to reproduce the bug:
Defining a structure (when class is defined instead of a struct, everything works as it should)
Adding memory alignment attribute (GCC requires it to be put in between keyword struct and structure name, adding it there produces the bug. I don't know if this shows up with different attributes/options added between struct and its name)
Wrapping TestClass in a namespace
TestClass structure must have some method definitions inside it (like in this example, constructors are one-line definitions. Moving them outside struct definition fixes the issue, however it requires to produce additional code, which is sometimes just not needed)
Thanks for the great job with astyle! I'm looking forward to hearing from you.
And sorry for the horrible reproduction list format! Here is the list in correct formatting:
similar to the initially reported issue:
results in:
...which in turn upsets the static code analyser
Seems like the issue is caused by the parentheses causing the struct declaration to be interpretted as a function declaration