public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Andrew Pinski <pinskia@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-3994] Improve error message for if with an else part while in switch
Date: Thu, 14 Sep 2023 14:30:16 +0000 (GMT)	[thread overview]
Message-ID: <20230914143017.1B0263858CDA@sourceware.org> (raw)

https://gcc.gnu.org/g:4241415b8817d505e92144175c040a48b1cf2b9f

commit r14-3994-g4241415b8817d505e92144175c040a48b1cf2b9f
Author: Andrew Pinski <apinski@marvell.com>
Date:   Tue Jul 11 22:14:18 2023 -0700

    Improve error message for if with an else part while in switch
    
    While writing some match.pd code, I was trying to figure
    out why I was getting an `expected ), got (` error message
    while writing an if statement with an else clause. For switch
    statements, the if statements cannot have an else clause so
    it would be better to have a decent error message saying that
    explictly.
    
    OK? Bootstrapped and tested on x86_64-linux-gnu.
    
    gcc/ChangeLog:
    
            * genmatch.cc (parser::parse_result): For an else clause
            of an if statement inside a switch, error out explictly.

Diff:
---
 gcc/genmatch.cc | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc
index a1925a747a7..03d325efdf6 100644
--- a/gcc/genmatch.cc
+++ b/gcc/genmatch.cc
@@ -4891,6 +4891,8 @@ parser::parse_result (operand *result, predicate_id *matcher)
 		    ife->trueexpr = parse_result (result, matcher);
 		  else
 		    ife->trueexpr = parse_op ();
+		  if (peek ()->type == CPP_OPEN_PAREN)
+		    fatal_at (peek(), "if inside switch cannot have an else");
 		  eat_token (CPP_CLOSE_PAREN);
 		}
 	      else

                 reply	other threads:[~2023-09-14 14:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230914143017.1B0263858CDA@sourceware.org \
    --to=pinskia@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).