# clang-format, how to align function declarations?

**URL:** <https://discourse.llvm.org/t/clang-format-how-to-align-function-declarations/31802>\
**Category:** Clang Frontend\
**Created:** [April 16, 2014, 6:14pm UTC](https://discourse.llvm.org/t/clang-format-how-to-align-function-declarations/31802 "2014-04-16T18:14:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Petteri\_Salo](https://avatars.discourse-cdn.com/v4/letter/p/7ba0ec/32.png) [@Petteri\_Salo](https://discourse.llvm.org/u/Petteri_Salo)\
**Post date:** [April 16, 2014, 6:14pm UTC](https://discourse.llvm.org/t/clang-format-how-to-align-function-declarations/31802/1 "2014-04-16T18:14:26Z")

</div>

Hello,

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”

Thanks,

Petteri Salo

---

<div class="post-metadata">

**Author:** ![Daniel\_Jasper](https://avatars.discourse-cdn.com/v4/letter/d/2acd7d/32.png) [@Daniel\_Jasper](https://discourse.llvm.org/u/Daniel_Jasper)\
**Post date:** [April 16, 2014, 6:44pm UTC](https://discourse.llvm.org/t/clang-format-how-to-align-function-declarations/31802/2 "2014-04-16T18:44:21Z")

</div>

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.

Cheers,  
Daniel
