Header inclusion ordering style addition

Lei YU mine260309 at gmail.com
Wed Aug 29 14:29:34 AEST 2018


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!

--
BRs,
Lei YU
On Wed, Aug 29, 2018 at 2:12 AM William Kennington <wak at google.com> wrote:
>
> As long as this can be done automatically with clang format it sounds
> good to me. It seems like the trivial alphabetical ordering built-in
> to clang-format works fine for the consistency element. We should get
> rid of all local includes and use system includes if the headers get
> installed as part of the packaging process.
> On Tue, Aug 28, 2018 at 10:54 AM James Feist
> <james.feist at linux.intel.com> wrote:
> >
> > On 08/28/2018 10:35 AM, Patrick Venture wrote:
> > > Each file in each daemon attempts to order the headers in a consistent
> > > way.  Typically, alphabetically.  However, I propose here a more
> > > explicit ordering:
> > >
> > > https://gerrit.openbmc-project.xyz/12180
> > >
> > > As an example of the ordering:
> > >
> > > https://gerrit.openbmc-project.xyz/11421
> > >
> >
> > This can be enforced in clang-format with SortIncludes
> > https://clang.llvm.org/docs/ClangFormatStyleOptions.html and
> > IncludeCategories regex for specific ordering.
> >
> > > I feel that having a consistent ordering that deals with the various
> > > types of header files included provides a couple benefits:
> > > * header files are included where you expect to find them
> > > * easily can see that there are c-headers included in a clean group
> > > * defines that the phosphor library headers are treated as normal cpp
> > > libraries and included in that grouping making the headers come across
> > > as system libraries and not something different.
> > >
> > > Please take a look.
> > >
> > > Patrick
> > >


More information about the openbmc mailing list