[Development] clang-format

Allan Sandfeld Jensen kde at carewolf.com
Wed Jun 20 15:08:29 CEST 2018


On Mittwoch, 20. Juni 2018 14:09:20 CEST Ivan Donchevskii wrote:
> One more thing about clang-format.
> 
> It might be really nice if we use it as a default formatting tool in Qt
> Creator. And I really want to experiment with it and see how clang-format
> can replace the indenter that we currently use (which has a lot of bug
> reports about broken formatting for example with modern C++).
> 

I never seen anything QtCreator had trouble with. But on the subject, there is 
one standard indentation features QtCreator has that clang-format can't 
reproduce. When you line-break an expression, clang-format will indent it a 
fixed amount from the beginning of the next line, where QtCreator will try to 
find places to line up with from the line above, including indenting from the 
last paranthesis For instance:

int a = foobar(x) + foo(looooooongfunctionname(
				         looongvariablename));

vs

int a = foobar(x) + foo(looooooongfunctionname(
    looongvariablename));


This semantic indentation is not something clang-format can do at the moment. 
At least if someone knows how, I would love to know, I have search everywhere, 
including the clang-format code. 

It is not so bad in this case, but once you have multiple line-break like that 
in a long function call, clang-formated code is essentionally just 
unformatted.

In any case if we want to enforce clang-format everywhere, perhaps we 
shouldn't have QtCreator do smarter and more readable indentation that we do 
not allow in our repository?

'Allan
							





More information about the Development mailing list