[Development] clang-format config file.

Dominik Holland dominik.holland at pelagicore.com
Thu Jun 30 13:01:30 CEST 2016

Hi Olivier,

Am 06/30/2016 um 12:52 PM schrieb Olivier Goffart:
> Hi,
> I have made a clang-format config file. I believe it should go into the 
> qtrepotools repository, so I made this pull request:
> https://codereview.qt-project.org/163941
> You can download this file from there and put it in the parent directory of 
> your qt repositories.  (clang-format search all the parent folders for a 
> .clang-format file)
> We don't want to reformat existing files, but this help to format only the 
> lines that are touched in a given commit.  The git-clang-format tool can be 
> used for that.
> The git-clang-format tool is part of the clang. So it is probably packaged in 
> your distribution as part of clang.
> To use it, simply commit as before, but before pushing, run:
>   git-clang-format HEAD^
>   git diff  
>   # look at the changes made by clang-format, possibly retify some of it
>   git commit -a --amend
> Then you can push.
> If you want to run git-clang-format on several commit separately, the --exec 
> feature of git rebase comes handy:
>   git rebase -i --exec "git-clang-format HEAD^"
> The rebase will stop if clang-format does changes so you can apply the changes 
> to that last commit and continue with git rebase --continue
> The conf file is based on the WebKit style which is the closest builtin style 
> to Qt. Then it was adjusted to fit better to the existing Qt style.
> It follows the style closely, but there are some cases that might not be 
> following existing practices. The question is if we want to try to fix clang-
> format to be able to cope with them, or simply adapt the coding style to fit 
> clang-format config.

I think it would be cool to have a built-in Qt config, as it would be
very convenient also for other developers which work with Qt.

> Some of the things that are not possible with clang-format if to have all the 
> function in one line like we sometimes have in our headers:
>   inline const QString operator+(const QString &s1, const QString &s2)
>   { QString t(s1); t += s2; return t; }
> The style disabled any re-wraping of the comments, because the qdoc rules are 
> not encoded in clang-format. So comments will not be touched.
> But in general, I have been trying it on a few commits and it works quite 
> well. You should try it as well and report the problems so they can be 
> addressed.

thx for uploading this.

We used clang-format in one of our projects and what we've seen is that
the clang-format version used for the formatting is important and can
lead to different results.

Which version did you use ?

Debian(unstable) is currently offering the following versions for me:

clang-format - Tool to format C/C++/Obj-C code
clang-format-3.5 - Tool to format C/C++/Obj-C code
clang-format-3.6 - Tool to format C/C++/Obj-C code
clang-format-3.7 - Tool to format C/C++/Obj-C code
clang-format-3.8 - Tool to format C/C++/Obj-C code
clang-format-3.9 - Tool to format C/C++/Obj-C code
clang-format-3.4 - Tool to format C/C++/Obj-C code

If the version is not packaged for your distribution you might be able
to download a binary version here: http://llvm.org/releases/download.html


Dominik Holland

Pelagicore AG
Balanstr. 55, 81541 Munich, Germany
+49 (0)171 760 25 96
dominik.holland at pelagicore.com

More information about the Development mailing list