[cfe-dev] [clang-format] Sort include does not handle pre-compiled headers well.

Nico Weber via cfe-dev cfe-dev at lists.llvm.org
Mon Dec 7 11:33:59 PST 2015


I'm curious about this too -- not just precompiled headers, other Windows
headers too.

>From a header-sorting script we use in Chromium:

  # The win32 api has all sorts of implicit include order dependencies
:-/  # Give a few headers special sort keys that make sure they appear
before all  # other headers.  if line.startswith('<windows.h>'):  #
Must be before e.g. shellapi.h    return '0'  if
line.startswith('<atlbase.h>'):  # Must be before atlapp.h.    return
'1' + line  if line.startswith('<ole2.h>'):  # Must be before e.g.
intshcut.h    return '1' + line  if line.startswith('<unknwn.h>'):  #
Must be before e.g. intshcut.h    return '1' + line


On Sun, Dec 6, 2015 at 1:17 PM, Jean-philippe Dufraigne via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Hi Daniel,
> Sorry, I sent the initial message to the wrong list.
>
> When using pre-compiled header, the Main Header for the file will not be
> detected since the first header needs to be the precompiled header.
>
> I was looking at fixing it, but I am not quite sure how to go fixing it?
>
> This will result in the main header being moved.
>
> Expected:
> MyFile.cpp:
>
>   #include "stdafx.h"
>   #include "MyFile.h"
>   #include "AnotherHeader.h"
>
> Actual:
> MyFile.cpp:
>
>   #include "stdafx.h"
>   #include "AnotherHeader.h"
>   #include "MyFile.h"
>
> This can be somewhat worked around by leaving a line after the Main Header.
>
> Fix Option 1:
> Add a new option: PercompiledHeaderRegEx, and if detected assign priority
> -1, and keep on looking for MainHeader (Not great since we use unsigned)
>
> Fix Option 2:
> Add a keyword that can be used instead of the regular expression to refer
> to the MainHeader. This way one can add a regular expression for the
> pre-compiled header priority 0, and one for MainHeader priority 1. Consider
> it main header if first header with category >= MainHeaderCategory.
>
> Fix Option 3:
> A better plan?
>
> Do you have any thought on the problem?
> Kind Regards,
> Jean-Philippe.
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20151207/e87f93d2/attachment-0001.html>


More information about the cfe-dev mailing list