How to make sure pch.h is the first included header using clang-format?

276 Views Asked by At

Some compilers require the pre-compiled-header to be included first. Clang-format can sort the headers (which is good). I want to make sure that pch will always be first.

How can I do this?

(My work around is to use IncludeBlocksStyle: Preserve and seperate #include "pch.h" from the rest.)

1

There are 1 best solutions below

1
sklott On BEST ANSWER

You can use negative priorities in IncludeCategories, so you can do something like this:

IncludeBlocksStyle: Regroup
IncludeCategories:
  - Regex: '"pch.h"'
    Priority: -1000
  # Other groups definitions here