[cfe-dev] clang-format option for formatting closing brace of initializer lists

Manuel Klimek via cfe-dev cfe-dev at lists.llvm.org
Mon Sep 11 01:11:38 PDT 2017


On Mon, Sep 11, 2017 at 9:41 AM Julian Andres Klode <jak at jak-linux.org>
wrote:

> On Mon, Sep 11, 2017 at 07:29:34AM +0000, Manuel Klimek wrote:
> > If you put a trailing comma on the line it does the right thing. Perhaps
> > you're on an old version?
>
> No, I just did not know :) Maybe it would be nice to have an option to
> do that automatically, but not sure. It does make sense.
>

You mean forcing a comma at the end? Generally clang-format tries not to
edit source code beyond whitespace. We've diverged from this in a couple of
places, but always very carefully and reluctantly :) I personally don't
think that option would carry the weight.


>
> >
> > On Sun, Sep 10, 2017 at 8:25 PM Julian Andres Klode via cfe-dev <
> > cfe-dev at lists.llvm.org> wrote:
> >
> > > Hi,
> > >
> > > is there a way to configure clang-format to break line before the end
> of an
> > > initializer list?
> > >
> > > So, not do this:
> > >
> > >    static const char *WaitingTasks[][6] = {
> > >        {"systemd-networkd.service",
> > > "/lib/systemd/systemd-networkd-wait-online", "-q", "--timeout=30",
> nullptr},
> > >        {"NetworkManager.service", "nm-online", "-q", "--timeout", "30",
> > > nullptr}};
> > >
> > > but rather this:
> > >
> > >    static const char *WaitingTasks[][6] = {
> > >        {"systemd-networkd.service",
> > > "/lib/systemd/systemd-networkd-wait-online", "-q", "--timeout=30",
> nullptr},
> > >        {"NetworkManager.service", "nm-online", "-q", "--timeout", "30",
> > > nullptr}
> > >    };
> > >
> > > (possibly with a trailing comma on the nm-online line for consistency).
> > >
> > > This style looks much cleaner to me. Somewhat unrelated, it's also the
> > > style gofmt uses.
> > >
> > > (Please To/CC on replies, not subscribed)
> > > --
> > > Debian Developer - deb.li/jak | jak-linux.org - free software dev
> > >                   |  Ubuntu Core Developer |
> > > When replying, only quote what is necessary, and write each reply
> > > directly below the part(s) it pertains to ('inline').  Thank you.
> > > _______________________________________________
> > > cfe-dev mailing list
> > > cfe-dev at lists.llvm.org
> > > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
> > >
>
> --
> Debian Developer - deb.li/jak | jak-linux.org - free software dev
>                   |  Ubuntu Core Developer |
> When replying, only quote what is necessary, and write each reply
> directly below the part(s) it pertains to ('inline').  Thank you.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170911/3a8211c6/attachment.html>


More information about the cfe-dev mailing list