[cfe-dev] Disable #error?

Kim Gräsman kim.grasman at gmail.com
Tue Jan 14 11:52:48 PST 2014


On Tue, Jan 14, 2014 at 8:37 PM, Jacob Carlborg <doob at me.com> wrote:
>
> I have a tool that translate C header files to D modules[1]. The tool is
> designed to translate header files one at the time. The problem is that in
> some C libraries some kind of umbrella headers are used. They only serve to
> include other sub header files. Some of these libraries enforce this by the
> sub header files checking for a preprocessor macro defined by the umbrella
> header. If this macro is not defined they halt the complication with the
> #error directive.

I have the exact same need for IWYU, but I want to use the #error
directive as a heuristic to figure out header mappings.

So if we see a private header with an #error directive, we could run a
regex over its message and find the umbrella header we should
recommend instead.

I'm almost sure it's not a reasonable way to do this, but my life
would be easier if there was a PPCallback method for #error where the
error message was passed as an argument, and I could signal back that
I wanted to continue processing without failing (e.g. through a bool).

I've also considered that maybe a DiagnosticConsumer could be hooked
up to see the #error messages, but I haven't really checked if it
would be possible. I don't think I could prevent #error from failing
anyway.

I don't know if either of these are available in libclang, though.

- Kim



More information about the cfe-dev mailing list