[cfe-dev] Should we build semantically invalid nodes?

Doug Gregor doug.gregor at gmail.com
Thu Oct 23 12:50:07 PDT 2008

On Thu, Oct 23, 2008 at 11:49 AM, Argiris Kirtzidis <akyrtzi at gmail.com> wrote:
> Doug Gregor wrote:
>>> Sema is *huge* and the alternative Action option is not realistic
>>> (another
>>> Action that deals with templates ? ;), this is what almost all of clients
>>> will use.
>>> There will be clients that care only about the syntax tree, Sema is fully
>>> capable of servicing them too.
>> Okay, that's my option (1), then. We don't really want to cater to
>> clients trying to work on ill-formed code, do we?
> I think you underestimate the importance of being able to get a syntax tree
> as complete as possible even on ill-formed code.

Yep, that's likely. I think you underestimate the amount of pain that
having invalid AST nodes will cause.

> There is certainly some middle ground to tread here, not all semantic checks
> will wreak havoc if they allow the expression; I think it's a worthwhile
> goal to strive to have an AST as complete as possible, it will be better in
> the long run for interesting uses of Clang beyond compiling.

If the AST node that is built is something that is valid for further
semantic processing (even if it resulted in diagnostics), that's fine.
So, if we're looking at Sebastian's casting patch, for example, I'm
fine with generating an AST node for a reinterpret_cast that casts
away constness, because the resulting expression is still usable for
type-checking. Anything that requires a "this is an invalid
expression" flag is, in my opinion, asking for trouble.

  - Doug

More information about the cfe-dev mailing list