[PATCH] Fix parser to recognize operator?:
Matthias Kretz
m.kretz@gsi.de
Mon Oct 14 08:29:00 GMT 2019
On Freitag, 11. Oktober 2019 16:17:09 CEST Marek Polacek wrote:
> On Fri, Oct 11, 2019 at 04:06:43PM +0200, Matthias Kretz wrote:
> > This is a minor bugfix for improved error reporting. Overloading ?: is
> > just as disallowed as it is without this change.
>
> Thanks. Can you provide a testcase that shows why this change makes sense?
> That testcase then should be part of the patch submission.
I can. Most (all?) testcases reference a PR. Should I open one?
>
> > 2019-10-11 Matthias Kretz <m.kretz@gsi.de>
> >
> > * gcc/cp/parser.c (cp_parser_operator): Parse operator?: as an
> >
> > attempt to overload the conditional operator. Then
> > grok_op_properties can print its useful "ISO C++ prohibits
> > overloading operator ?:" message instead of the cryptic error
> > message about a missing type-specifier before '?' token.
> >
> > diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
> > index 3ee8da7db94..73385cb3dcb 100644
> > --- a/gcc/cp/parser.c
> > +++ b/gcc/cp/parser.c
> > @@ -15502,6 +15502,15 @@ cp_parser_operator (cp_parser* parser, location_t
> > start_loc)
> >
> > op = COMPONENT_REF;
> > break;
> >
> > + case CPP_QUERY:
> > + op = COND_EXPR;
> > + /* Consume the `?'. */
> > + cp_lexer_consume_token (parser->lexer);
> > + /* Look for the matching `:'. */
> > + cp_parser_require (parser, CPP_COLON, RT_COLON);
> > + consumed = true;
> > + break;
> > +
> >
> > case CPP_OPEN_PAREN:
> > {
> >
> > /* Consume the `('. */
>
> --
> Marek Polacek • Red Hat, Inc. • 300 A St, Boston, MA
--
──────────────────────────────────────────────────────────────────────────
Dr. Matthias Kretz https://mattkretz.github.io
GSI Helmholtzzentrum für Schwerionenforschung https://gsi.de
SIMD easy and portable https://github.com/VcDevel/Vc
──────────────────────────────────────────────────────────────────────────
More information about the Gcc-patches
mailing list