ccache + clang warnings that are suppressed during macro expansion

Recently, a user reported to me a problem when using ccache and clang. The issue is simple:

(1) Clang suppresses some warnings in macro expansions, e.g. -Wparentheses-equality.

(2) ccache produces preprocessed files that it uses for caching.

The combination of:

  (1) + (2)

results in ccache + clang sometimes producing more warnings than one just uses the compiler on its own.

I'm sure this is a known issue, but has this been raised before? If not, any ideas on how we should solve this? Is this something ccache should deal with, something clang should handle, or both? I'm on the fence here myself, and would appreciate any opinions or suggestions.


(1) Clang suppresses some warnings in macro expansions, e.g. -Wparentheses-equality.

That seems rather not good. Do we do this deliberately (if so, why?), or is it just an accident/bug?

  • David

This is no accident. I don’t have an exhaustive list, but we do this in several cases. The argument is that some warnings are almost always false positives when they result from macro expansions, but are very useful otherwise. This of course leads to the problem that preprocessed files can have more warnings than the original source, but it does allow us to be more aggressive about putting various warnings under -Wall.

Could -E mode insert #pragmas to disable these warnings for source
that originates from macro expansions? That way, when clang recompiles
its preprocessed output, it shows the same warnings it showed the
first time round, which seems nice independent of ccache.

(I'm not sure many people ran into this so far – when we started using
ccache in chromium a few weeks ago, we had to add code to both clang
and ccache to make it work at all. We have since switched away from
ccache, but back when we used it we found all the "unused commandline
flags" that arise from this combination more annoying.)


I think this is "behaves correctly". It is possible but impractical for -E output to include information about tokens "expanded from a macro".


AFAIK, moder ccache doesn't use compiler's -E mode in any way by default.