On Mon, 15 Sep 2014, Marek Polacek wrote:

> On Mon, Sep 15, 2014 at 05:49:25PM +0000, Joseph S. Myers wrote:
> > On Mon, 15 Sep 2014, Marek Polacek wrote:
> > 
> > > We must be careful to properly handle code such as "1 //**/ 2", which
> > > has a different meaning in C90 and GNU90 mode.  New testcases test this.
> > 
> > I don't think there's sufficient allowance here for other valid cases.  
> > It's valid to have // inside #if 0 in C90, for example, so that must not 
> > be diagnosed (must not have a pedwarn or error, at least, that is).  It's 
> 
> Good point, sorry about that.  Luckily this can be fixed just by
> checking pfile->state.skipping.  New test added.

This is getting closer, but it looks like you still treat it as a line 
comment when being skipped for C90, when actually it's not safe to treat 
it like that; you have to produce a '/' preprocessing token and continue 
tokenizing the rest of the line.  Consider the following code:

int i = 0
#if 0
// /*
#else
// */
+1
#endif
;

For C90 i gets value 0.  With // comments it gets value 1.

> +       /* In C89/C94, C++ style comments are forbidden.  */
> +       else if ((CPP_OPTION (pfile, lang) == CLK_STDC89
> +                 || CPP_OPTION (pfile, lang) == CLK_STDC94))
> +         {
> +           /* But don't be confused about // immediately followed by *.  */
> +           if (buffer->cur[1] == '*'
> +               || pfile->state.in_directive)

And this comment needs updating to reflect that it's not just //* where // 
can appear in valid C90 code in a way incompatible with treating it as a 
comment.

-- 
Joseph S. Myers
jos...@codesourcery.com

Reply via email to