[cfe-dev] clang-format: Patches and Questions

Joel Holdsworth joel.holdsworth at vcatechnology.com
Mon Nov 11 05:04:05 PST 2013


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dear All

I hope this is the right list to post to.

I've been experimenting with clang-format to find whether it will suit
our needs. I must say it's pretty impressive work. I like it a lot.

The only problem is that some of the styling we want to use isn't
supported yet. So I started trying to add support for the things we need
with varying degrees of success.

So far I've added 2 features:

The first is AttachNamespaceBraces. This overrides the normal
brace-attachment rules for namespaces (e.g. Allman), forcing the
egyptian braces for namespaces.

The second is ContinuationAlignment. This can either be:
AlignToParenthesis (the current behaviour)...

void foo_bar_foo_bar_foo_bar_foo_bar_foo(int a, int b, int c, int d, int e,
                                         int f, int g, int h, int i, int j,
                                         int k, int l, int m, int n, int o,
                                         int p, int q, int r, int s, int s,
                                         int u, int v, int w, int x)
{
  if (far_too_long_variable_names_are_painful ==
        far_too_long_variable_names_are_painful ||
      (far_too_long_variable_names_are_painful !=
       far_too_long_variable_names_are_painful))
    exit(1);
}

...and SingleIndent:

void foo_bar_foo_bar_foo_bar_foo_bar_foo(int a, int b, int c, int d, int e,
  int f, int g, int h, int i, int j, int k, int l, int m, int n, int o,
int p,
  int q, int r, int s, int s, int u, int v, int w, int x)
{
  if (far_too_long_variable_names_are_painful ==
    far_too_long_variable_names_are_painful ||
    (far_too_long_variable_names_are_painful !=
    far_too_long_variable_names_are_painful))
    exit(1);
}

These patches are published here: https://github.com/jhol/clang/commits/work
Could someone review the design and implementation of these?

There a few other things I'd like to have. Could anyone give me any
pointers about how to achieve these things?

1. The colon for initialiser lists is in the wrong position for our
style. We have it like this, attached to the line above:

Foo::Foo() :
  _first(1),
  _second(2)
{
}

I tried to figure out how to make this change, and failed.

2. For some reason clang-format deletes the empty line after after the
last function in a namespace:

namespace foo {

void bar()
{
}
}

Is it possible to correct this?

3. Astyle has a --remove-brackets feature that can removed the braces
from single line if statements:

Converting this...

if (1)
{
  do_something();
}
else
{
  do_something_else();
}

...to this....

if (1)
  do_something();
else
  do_something_else();


Thanks
Joel Holdsworth
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJSgNXFAAoJECNPIH+lv1juwR8P/AiVPYIUsP7nyWMIT9PfG69L
8GP3i0fO6ag6vvqtXJkiNIxT4NkNobmkLrj/XXzEkflQK/UdV0TD00H/nHSILJX0
tbrDZ5quf8vYHy/0y/hft8VsvZaEMRQfyEzRccQ93lPxE3Xi37CVQlquZBcbNswA
/wuYKsFD+9dlBhnhm3c7Itdr2cHmqkmnMlI4NRCrhA3H/fJYmEIc/bddwu8Lo612
mPt/CypkZEiObn6fTrbpRRGu7P/xVkTj8dV8Ey0E9SJpqF02tpG9ZwKuZtDENmdd
0DGBParKtiJhxffomYU+QaJ0Wu3n6kElDQ9wZhH2iRGtBl9CpfLc04AtT0/XBvjQ
qf5lcyPdBC9ChaRPvlfsxxaS62nheBTcolESk965dCzA14wDnM/QDTjEiV4Iw5FG
f4oeVh7W5OG5i3+bU0TJipjioDXKJtxY+ABStjliEGlabrizgvxHs3ewGszrIy7F
0u4Yb8vAMow8GJaBYXFv3pIQhS9NEa/QP0VlF5KpiTxvfGUvn5YTK33yxN0G9nFx
zWlfDQkjotjAic6uYgFR8u8PVYZX96NdSY9p6v1f6v28H1lXs+/a1Dx1O57nOEu+
iYd+x8G3M+9mA6l2o7YhakA9kezNRSpHhFV5U5QrJJJWMsF8B3Z1o1mpZ5MgFZmy
LAB6nmQ9WLVMYOiLdfET
=DACj
-----END PGP SIGNATURE-----




More information about the cfe-dev mailing list