r212591 - clang-format: Revamp function declaration/definition indentation.

Chandler Carruth chandlerc at google.com
Wed Jul 9 02:01:23 PDT 2014


I significantly prefer the new formatting FWIW.

I don't like continuations without indent at all. I'm willing to concede
the necessity of them for functions, but for variables it feels quite bad
to me.

An example of where the old behavior was very confusing for me, let's take
the following code:

static llvm::cl::opt<whatever> MyLongOptionName(args, more_args, "yadda
yadda");

If we end up (due to the specific balance of string length above) breaking
before "MyLongOptionName" we get no indent. But if we break after the "("
we get 4 spaces of indent. This is even weirder if your variable doesn't
use a "type name(arg, arg);" style of initialization, but instead is "type
name = a + b;" as now 'name' would get no indent but 'a' as the start of
the second line would get indent. I understand the C++ grammar rules which
lead to that scenario, but find it really awkward when reading code.

With the new logic, there is one rule for all indentation when breaking a
variable declaration across multiple lines: 4 spaces of indent. There is
also one rule for indentation when breaking after the return type of a
function: no indent.


On Wed, Jul 9, 2014 at 1:47 AM, Daniel Jasper <djasper at google.com> wrote:

> Yes, this is intended and I actually don't think that it is such a big
> difference. Multiline variable declaration that are broken after the type
> are actually reasonably rare.
>
> Happy, to take a vote on this though..
>
>
> On Wed, Jul 9, 2014 at 10:42 AM, Tobias Grosser <tobias at grosser.es> wrote:
>
>> On 09/07/2014 09:50, Daniel Jasper wrote:
>>
>>> Author: djasper
>>> Date: Wed Jul  9 02:50:33 2014
>>> New Revision: 212591
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=212591&view=rev
>>> Log:
>>> clang-format: Revamp function declaration/definition indentation.
>>>
>>> Key changes:
>>> - Correctly (well ...) distinguish function declarations and variable
>>>    declarations with ()-initialization.
>>> - Don't indent when breaking function declarations/definitions after the
>>>    return type.
>>> - Indent variable declarations and typedefs when breaking after the
>>>    type.
>>>
>>> This fixes llvm.org/PR17999.
>>>
>>
>> I think this commit changed the formatting of global command line
>> declarations in LLVM:
>>
>> static cl::opt<bool>
>> DetectScopsWithoutLoops("polly-detect-scops")
>>
>> became:
>>
>> static cl::opt<bool>
>>     DetectScopsWithoutLoops("polly-detect-scops")
>>
>> and
>>
>> static cl::opt<std::string>
>> OnlyFunction("polly-only-func")..
>>
>> became
>>
>>
>> static cl::opt<std::string> OnlyFunction(
>>     "polly-only-func")
>>
>> I personally was very happy with the previous formatting. Was this change
>> intended?
>>
>> As this introduces a large difference compared to clang-format-3.4, I
>> would prefer to keep the existing style.
>>
>> Tobias
>>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140709/47836080/attachment.html>


More information about the cfe-commits mailing list