This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C PATCH] Better diagnostics for C++ comments in C90 (PR c/61854)
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Marek Polacek <polacek at redhat dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 16 Sep 2014 22:32:51 +0000
- Subject: Re: [C PATCH] Better diagnostics for C++ comments in C90 (PR c/61854)
- Authentication-results: sourceware.org; auth=none
- References: <20140915171617 dot GG23226 at redhat dot com> <Pine dot LNX dot 4 dot 64 dot 1409151742130 dot 16736 at digraph dot polyomino dot org dot uk> <20140915210035 dot GH23226 at redhat dot com>
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
joseph@codesourcery.com