[PATCH] D53866: [Preamble] Fix preamble for circular #includes

Ilya Biryukov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 31 13:54:01 PDT 2018


ilya-biryukov added a comment.

In https://reviews.llvm.org/D53866#1282582, @yvvan wrote:

> @ilya-biryukov 
>  As far as I understand the problem the same thing happens when you are in the header a.h which includes b.h and b.h includes a.h at the same time. So you get this recursion indirectly and very often because that's why include guards are there.


Cycles in include graphs are almost always unintentional and must be broken apart, there are very few cases where you actually want this.
E.g. in your example, since 'b.h' includes 'a.h' it needs something from 'a.h'. But if you include 'b.h' while processing the preamble of 'a.h', the declarations inside 'a.h' are not yet visible and that would result in (at times obscure and hard to read) compiler errors when parsing 'b.h'.
(Assuming a.h and b.h are normal headers and the use-case does not involve doing various preprocessor tricks)

In those cases it usually works by accident (e.g. when 'b.h' included 'a.h', but never actually used anything declared in 'a.h').


Repository:
  rC Clang

https://reviews.llvm.org/D53866





More information about the cfe-commits mailing list