[PATCH] D26943: [CodingStandards] Add style guide rule about "if" statements and loops.

Mehdi AMINI via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 25 12:36:36 PST 2016


mehdi_amini added a comment.

In https://reviews.llvm.org/D26943#605378, @kparzysz wrote:

> My concern about automatic formatting is that it may damage context-specific formatting. Consider this example:
>  [...]


For specific cases (formatting table, etc.), you can disable clang-format by marking the begin/end of the section with a comment, see for example https://github.com/llvm-mirror/lldb/blob/master/source/Commands/CommandObjectType.cpp#L101

> If at one point we decided that single-line if/for/while statements should also be bracketed, would we require that in a new code added to a file that consistently didn't have them? If so, it would be inconsistent with the existing code, if not, it would contravene the guidelines.

I *always* clang-format the statement I change in my patch, irrespectively of the rest of the file. Hopefully with time we'll touch enough lines that non-conformant code will slowly disappear.
I've also seen people clang-formatting a file as a whole as a pre-step before performing large changes to it.

> Sweeping changes throughout the code base are a real pain for out-of-tree developers, so hopefully that wouldn't be considered.

We are quite consistent about not limiting ourselves upstream to "please" out-of-tree developers, I wouldn't take this into consideration here either. (See also for example the recent massive clang-formatting change in LLDB, where they reformatted the full codebase in a single commit.)


https://reviews.llvm.org/D26943





More information about the llvm-commits mailing list