Detecting #error directive inside #if block


I'm toying with the idea of detecting and parsing user diagnostics to
help IWYU guess which is the public header for a given private header.

For example, glib has the following convention:

#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."

Essentially I would like to trap all #error directives within a #if,
#ifdef or #ifndef, scan the raw message for a pattern and extract the
quoted include name. This would be an optional heuristic, but I think
it could be made to work reasonably well in the general case.

Is there a way to use PPCallbacks for this? I noticed there's no
PPCallback for #error, but even given that I'm not sure if I can
reason about structure in the preprocessor (like I would in the AST),
e.g. find the nearest #if block.

Any ideas?

- Kim

OK, I think I see where I'm going wrong with this reasoning: the clang
preprocessor doesn't see through preprocessor conditionals, right?

So if the #error never triggers, I won't be able to spy into it using
the Lexer/PP. Did I get that right?

Do I have any options besides a regex over the entire file?

- Kim