summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2016-05-05 13:26:59 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2016-05-05 13:26:59 +0000
commit871164c49702d88e6364a827c66e87190e45a992 (patch)
treeb1c40179c0f161d00823019b5aa3295ab05f47ee
parent71474e9d7272d66fb32842e9efb9bd03d4a34a48 (diff)
downloadgcc-871164c49702d88e6364a827c66e87190e45a992.tar.gz
* c-parser.c (c_parser_switch_statement): Add IF_P argument,
parse it through to c_parser_c99_block_statement. (c_parser_statement_after_labels): Adjust c_parser_switch_statement caller. * parser.c (cp_parser_selection_statement): For RID_SWITCH, pass if_p instead of NULL to cp_parser_implicitly_scoped_statement. * c-c++-common/Wdangling-else-4.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@235920 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/c/ChangeLog7
-rw-r--r--gcc/c/c-parser.c8
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/parser.c2
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/c-c++-common/Wdangling-else-4.c31
6 files changed, 52 insertions, 5 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 1e77ef5e40f..49c9064854f 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,10 @@
+2016-05-05 Jakub Jelinek <jakub@redhat.com>
+
+ * c-parser.c (c_parser_switch_statement): Add IF_P argument,
+ parse it through to c_parser_c99_block_statement.
+ (c_parser_statement_after_labels): Adjust c_parser_switch_statement
+ caller.
+
2016-05-04 Marek Polacek <polacek@redhat.com>
* c-parser.c (c_parser_if_statement): Replace OPT_Wparentheses with
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index d275f8ef594..6523c08d63f 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -1305,7 +1305,7 @@ static void c_parser_statement (c_parser *, bool *);
static void c_parser_statement_after_labels (c_parser *, bool *,
vec<tree> * = NULL);
static void c_parser_if_statement (c_parser *, bool *, vec<tree> *);
-static void c_parser_switch_statement (c_parser *);
+static void c_parser_switch_statement (c_parser *, bool *);
static void c_parser_while_statement (c_parser *, bool, bool *);
static void c_parser_do_statement (c_parser *, bool);
static void c_parser_for_statement (c_parser *, bool, bool *);
@@ -5138,7 +5138,7 @@ c_parser_statement_after_labels (c_parser *parser, bool *if_p,
c_parser_if_statement (parser, if_p, chain);
break;
case RID_SWITCH:
- c_parser_switch_statement (parser);
+ c_parser_switch_statement (parser, if_p);
break;
case RID_WHILE:
c_parser_while_statement (parser, false, if_p);
@@ -5570,7 +5570,7 @@ c_parser_if_statement (c_parser *parser, bool *if_p, vec<tree> *chain)
*/
static void
-c_parser_switch_statement (c_parser *parser)
+c_parser_switch_statement (c_parser *parser, bool *if_p)
{
struct c_expr ce;
tree block, expr, body, save_break;
@@ -5605,7 +5605,7 @@ c_parser_switch_statement (c_parser *parser)
c_start_case (switch_loc, switch_cond_loc, expr, explicit_cast_p);
save_break = c_break_label;
c_break_label = NULL_TREE;
- body = c_parser_c99_block_statement (parser, NULL/*if??*/);
+ body = c_parser_c99_block_statement (parser, if_p);
c_finish_case (body, ce.original_type);
if (c_break_label)
{
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 74df11011fc..9006b341a7a 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+2016-05-05 Jakub Jelinek <jakub@redhat.com>
+
+ * parser.c (cp_parser_selection_statement): For RID_SWITCH,
+ pass if_p instead of NULL to cp_parser_implicitly_scoped_statement.
+
2016-05-04 Marek Polacek <polacek@redhat.com>
* parser.c (cp_parser_selection_statement): Replace OPT_Wparentheses
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index da2ee3cf1dc..f4c6f74b3d0 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -10978,7 +10978,7 @@ cp_parser_selection_statement (cp_parser* parser, bool *if_p,
in_statement = parser->in_statement;
parser->in_switch_statement_p = true;
parser->in_statement |= IN_SWITCH_STMT;
- cp_parser_implicitly_scoped_statement (parser, NULL,
+ cp_parser_implicitly_scoped_statement (parser, if_p,
guard_tinfo);
parser->in_switch_statement_p = in_switch_statement_p;
parser->in_statement = in_statement;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index ea73617155f..7eefd9445a3 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2016-05-05 Jakub Jelinek <jakub@redhat.com>
+
+ * c-c++-common/Wdangling-else-4.c: New test.
+
2016-05-04 Jakub Jelinek <jakub@redhat.com>
PR c++/70906
diff --git a/gcc/testsuite/c-c++-common/Wdangling-else-4.c b/gcc/testsuite/c-c++-common/Wdangling-else-4.c
new file mode 100644
index 00000000000..12cc1405a40
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/Wdangling-else-4.c
@@ -0,0 +1,31 @@
+/* { dg-do compile } */
+/* { dg-options "-Wdangling-else" } */
+
+void bar (int);
+
+void
+foo (int a, int b, int c)
+{
+ if (a) /* { dg-warning "suggest explicit braces to avoid ambiguous .else." } */
+ switch (b)
+ case 0:
+ if (c)
+ bar (1);
+ else
+ bar (2);
+}
+
+void
+baz (int a, int b, int c)
+{
+ if (a)
+ switch (b)
+ {
+ case 0:
+ if (c)
+ bar (1);
+ }
+ else
+ bar (2);
+}
+