Header inclusion ordering style addition

Patrick Venture venture at google.com
Thu Aug 30 01:24:17 AEST 2018


On Tue, Aug 28, 2018 at 11:51 PM Tanous, Ed <ed.tanous at intel.com> wrote:
>
> >
> > There is certain case that a header file is expected to be included before
> > others, e.g. config.h generated by autotool shall be included before other
> > local header files, to ensure that the configs are correctly defined.
> > E.g.
> >
> >     #include "config.h"
> >     #include "bar.hpp"
> >
> > Will clang-format re-format the order on the above case? If yes, I have
> > concern that it could introduce issues, e.g. compile error about undefined
> > symbols.
> > If clang-format handles it well, it's great!
>
> If clang-format is told to operate this way, it will.  It uses regex matched "priorities" then falls back to alphabetical.  If config.h needs to be first, it just needs to be put in the appropriate spot in the .clang-format file that everyone uses.

You can set a config.h to go ahead of all headers, even the main
source header by setting its priority specifically to -1, since 0 is
used for the main source header.

>
> I agree with the other sentiments that so long as it's done via clang-format, feel free to impose whatever header order is desired.


More information about the openbmc mailing list