Project

General

Profile

Actions

Task #3895

open

Write a style file for clang-format

Added by Nicholas Gordon almost 8 years ago. Updated almost 2 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:

Description

Clang-format is a tool that reformats C++ code (among other languages) according to a configuration file. The program is expressive and useful, and it would be a good extension to the toolchain.

Currently, the system has some limitations. According to Davide Pesavento:

  • "break-after-return-type" doesn't work on overloaded operators, they are not considered functions, thus the rule isn't applied. Fixed in clang-format 10
  • constexpr/explicit/virtual are not considered return types (and rightly so), but this means that constexpr/explicit constructors and virtual destructors are reformatted all on one line. This is minor and I think we can adapt our code style.
  • In lambda expressions, clang-format always removes the space between capture list and param list. This is very minor and we can adapt our style.
  • clang-format gets very confused by macros such as PUBLIC_WITH_TESTS_ELSE_PRIVATE (I guess it doesn't expand them) and it makes a terrible mess with the lines that follow, until it encounters another access specifier or the end of the class declaration. With clang-format 10, this behavior can be improved by adding these macros to StatementMacros. Even then, it's still less than ideal because AccessModifierOffset is not applied, but maybe we can live with it.
  • The alignment of "<<" after a line break within a logging macro is not what you would expect. One potential workaround is to list all logging macros in WhitespaceSensitiveMacros, but that disables formatting completely inside those macros.
  • Enums containing few short enumerators that could fit in one line are reformatted to be all on the same line. This was made configurable via AllowShortEnumsOnASingleLine in clang-format 11
  • It would be nice if we could enable AlignConsecutiveAssignments for enums only.

We should also take a look at uncrustify.

Actions #1

Updated by Davide Pesavento almost 8 years ago

  • Subject changed from Writing a clang-format configuration file to Write a style file for clang-format
  • Description updated (diff)
  • Start date deleted (12/19/2016)
Actions #2

Updated by Davide Pesavento almost 8 years ago

Nicholas Gordon wrote:

At least a few of these could be fixed with clever use of a lexer or similar, perhaps a Perl or Python script. However, unless there is someone who wants to manage the extra parts, it could be unmaintainable.

No, I think the only viable approach is to implement the features we need in clang-format and submit our patches upstream.

Actions #3

Updated by Alex Afanasyev almost 8 years ago

I did a few patches to clang-format that got a bit closer to our format (https://github.com/cawka/clang), but didn't push upstream (no cycles for that yet).

Actions #4

Updated by Junxiao Shi over 7 years ago

  • Category set to Docs
Actions #5

Updated by Davide Pesavento almost 7 years ago

  • Description updated (diff)
Actions #6

Updated by Davide Pesavento over 4 years ago

  • Description updated (diff)
Actions #7

Updated by Davide Pesavento over 4 years ago

  • Description updated (diff)
Actions #8

Updated by Davide Pesavento about 4 years ago

  • Tags set to needs-discussion
Actions #9

Updated by Davide Pesavento almost 2 years ago

  • Description updated (diff)
  • Category deleted (Docs)
Actions

Also available in: Atom PDF