[cfe-dev] PCH: separation from source header

Douglas Gregor dgregor at apple.com
Thu Sep 23 07:42:57 PDT 2010


On Sep 23, 2010, at 3:17 AM, Argyrios Kyrtzidis wrote:

> On Sep 22, 2010, at 1:56 AM, Ilya Murav'jov wrote:
> 
>> Argyrios Kyrtzidis пишет:
>>> On Sep 18, 2010, at 6:20 PM, Ilya Murav'jov wrote:
>>> 
>>>> 2) Is it possible to use Clang' PCH in the test case above? If not then
>>>> what is a solution?
>>> 
>>> $ clang -c -Isrc -include build/test.h -o build/test.o src/test.c
>>> 
>>> -Argiris
>>> 
>>>> 3) What is the reason against using .h.pch automatically like gcc
>> does it?
>>>> 
>> 
>> Ok, with Clang 2.9 I succeeded in building my project with PCH, thanks.
>> I have 2 things to say.
>> 
>> 1. I have to say that "-include" scheme is not so flexible as using PCH
>> automatically, really. Here is my use case: let's say I have a project
>> (a bunch of sources), and I want to use one PCH-file for it (and so on,
>> one PCH-file per project). So I set that "-include" option for the
>> project and now it is used for every source file in the project, without
>> an exception,- that is no so good! In several cases I do want to avoid it:
>> - my projects have C++ and C sources together; I can't use C++ PCH
>> header for C sources (so the hack is done - "-include" goes to CXX
>> options, not CPP ones).
> 
> Automatically using PCH seems like an architectural change with little benefit.
> Most of your woes can be attributed to the fact that clang does not fallback to the source header when it can't use the PCH.
> I think we should change the cannot-use-PCH errors to warnings and fallback to the source header, and maybe add a command-line option to enable the current behavior (hard errors when PCH can't be used).
> Anyone have an objection about this ?

We explicitly didn't do this because the build system should never be telling Clang to use a PCH file if it isn't correct.  However, so long as it's a remappable warning, it would be okay to make this change.

	- Doug





More information about the cfe-dev mailing list