]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Improve error message for if with an else part while in switch
authorAndrew Pinski <apinski@marvell.com>
Wed, 12 Jul 2023 05:14:18 +0000 (22:14 -0700)
committerAndrew Pinski <apinski@marvell.com>
Thu, 14 Sep 2023 14:29:43 +0000 (07:29 -0700)
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.

gcc/genmatch.cc

index a1925a747a7351ea4c5168bccaa857436f93ed93..03d325efdf6e349359c2df022e80ff35cc7f3ad9 100644 (file)
@@ -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