On Thu, Apr 21, 2022 at 18:59:56 +0100, Iain Sandoe wrote:
> Hi Ben,
>
> > On 21 Apr 2022, at 13:05, Ben Boeckel via Gcc <[email protected]> wrote:
> >
> > On Thu, Apr 21, 2022 at 06:05:52 +0200, Boris Kolpackov wrote:
> >> I don't think it is. A header unit (unlike a named module) may export
> >> macros which could affect further dependencies. Consider:
> >>
> >> import "header-unit.hpp"; // May or may not export macro FOO.
>
> 1. If you know how this was built, then you could do an -E -fdirectives-only
> build (both
> GCC and clang support this now) to obtain the macros.
My understanding is that how it gets used determines how it should be
made for Clang (because the consumer's `-D`, `-W`, etc. flags matter). I
do not yet know how I am to support this in CMake.
> 2. I suppose we could invent a tool (or FE mode) to dump the macros exported
> by a HU ***
Fun considerations:
- are `-D` flags exported? `-U`?
- how about this if `value` is the same as or different from the
at-start expansion:
```c++
#undef SOME_MACRO
#define SOME_MACRO value
```
- how about `#undef FOO`?
> >> #ifdef FOO
> >> import "header-unit2.hpp"
> >> #endif
> >
> > I agree that the header needs to be *found*, but scanning cannot require
> > a pre-existing BMI for that header. A new mode likely needs to be laid
> > down to get the information necessary (instead of just piggy-backing on
> > `-E` behavior to get what I want).
>
> perhaps that means (2)?
Can't it just read the header as if it wasn't imported? AFAIU, that's
what GCC did in Jan 2019. I understand that CPP state is probably not
easy, but something to consider.
> *** it’s kinda frustrating that this is hard infomation to get as a
> developer, so
> perhaps we can anticipate users wanting such output.
I think cacheing and distributed build tools are the most likely
consumers of such information.
--Ben