[PATCH] D106394: [clang][pp] adds '#pragma include_instead'

Kim Gräsman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 3 03:44:30 PDT 2021


kimgr added a comment.

Hi, sorry I'm late to the game. IWYU maintainer here.

I saw this patch mentioned in the LLVM Weekly newsletter and immediately thought: "wow, great, I have to build support in IWYU for that!".

I too prefer pragmas to magic comments, and I don't think `include_instead` necessarily needs to cover all IWYU pragmas (https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/IWYUPragmas.md).

Took me a while to get my head around it, but I see now that this is only supported for system headers. I think that makes sense for the compiler, otherwise it will be hard to guess which headers are allowed to include what. IWYU usually doesn't have that problem, as we analyze source files individually, and usually not headers independently.

My only concern was spelling -- in IWYU we need some handholding to know whether to use angled or quoted includes, but I see the quoting is part of the pragma, so that should be nice and useful.

Does this support the macro-able `_Pragma` syntax, so that users can be portable using something like:

  #ifdef __clang__
  #define INCLUDE_INSTEAD(headername) _Pragma("clang include_instead " ## headername)
  #else
  #define INCLUDE_INSTEAD(headername)
  #endif

? That might also make a nice testcase.

I'd love it if you could keep me in the loop if you want to extend this to something more general (using something like e.g. `IWYU pragma: friend`)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106394/new/

https://reviews.llvm.org/D106394



More information about the cfe-commits mailing list