public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix parser to recognize operator?:
@ 2019-10-11 14:14 Matthias Kretz
  2019-10-11 14:17 ` Marek Polacek
  0 siblings, 1 reply; 7+ messages in thread
From: Matthias Kretz @ 2019-10-11 14:14 UTC (permalink / raw)
  To: gcc-patches

This is a minor bugfix for improved error reporting. Overloading ?: is just as 
disallowed as it is without this change.

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 `('.  */

-- 
──────────────────────────────────────────────────────────────────────────
 Dr. Matthias Kretz                           https://mattkretz.github.io
 GSI Helmholtzzentrum für Schwerionenforschung             https://gsi.de
 SIMD easy and portable                     https://github.com/VcDevel/Vc
──────────────────────────────────────────────────────────────────────────

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-11-06 16:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-11 14:14 [PATCH] Fix parser to recognize operator?: Matthias Kretz
2019-10-11 14:17 ` Marek Polacek
2019-10-14  8:29   ` Matthias Kretz
2019-10-14 10:35   ` Matthias Kretz
2019-10-24  9:12     ` Dr. Matthias Kretz
2019-11-06 14:44     ` Ping2: " Matthias Kretz
2019-11-06 16:07     ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).