clang-format, how to align function declarations?


Can someone give me some pointers about where to look in the clang-format sources to make a modification which would allow alignment of the function names in a group of function declarations.

Or tell me if it is impossible without significant re-write, in other words not doable after work and family.

For example:

class FooBar
// these three function declarations belong to “group A”
char* doo();
const char* daa();
const SomeReallyLongTypeName& dii();

// these three function declarations belong to “group B”
void someMoreDoo();
int notSoMuchDaa();

In a real scenario the comment lines with “group x” would not be present.

The end result I’m looking for is:

  • The names of the three functions in the group A would start at the same column, i.e. doo() and daa() would align with dii().
  • The name notSoMuchDaa() would align with someMoreDoo()

the comment line with dashes (//----- ) would signify “end of group”


Petteri Salo

Such an alignment is quite contrary to how clang-format currently operates and it will be a significant change to implement this. It would somewhat relate to how we align trailing comments and escaped newlines, but significantly more complex. You would mostly need to change lib/Format/WhitespaceManager.cpp.