This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH for c++/70639 (ICE-on-valid with -Wmisleading-indentation and switch)
- From: Marek Polacek <polacek at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>, David Malcolm <dmalcolm at redhat dot com>
- Date: Wed, 13 Apr 2016 17:31:18 +0200
- Subject: PATCH for c++/70639 (ICE-on-valid with -Wmisleading-indentation and switch)
- Authentication-results: sourceware.org; auth=none
This is an ICE-on-valid-though-weirdo (TM) problem. We were trying to warn
about misleading indentation for a switch statement, but guard_tinfo_to_string
doesn't know what to do with RID_SWITCH and so a crash ensues. Rather than
teaching it about RID_SWITCH I think this warning can't usefully warn about
switch statements at all, similarly to do-while constructs.
David, what do you think?
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2016-04-13 Marek Polacek <polacek@redhat.com>
PR c++/70639
* c-indentation.c (should_warn_for_misleading_indentation): Bail out
for switch statements, too.
* c-c++-common/Wmisleading-indentation-4.c: New test.
diff --git gcc/c-family/c-indentation.c gcc/c-family/c-indentation.c
index 1da3f68..8c33686 100644
--- gcc/c-family/c-indentation.c
+++ gcc/c-family/c-indentation.c
@@ -239,10 +239,11 @@ should_warn_for_misleading_indentation (const token_indent_info &guard_tinfo,
if (line_table->seen_line_directive)
return false;
- /* We can't usefully warn about do-while statements since the bodies of these
- statements are always explicitly delimited at both ends, so control flow is
- quite obvious. */
- if (guard_tinfo.keyword == RID_DO)
+ /* We can't usefully warn about do-while and switch statements since the
+ bodies of these statements are always explicitly delimited at both ends,
+ so control flow is quite obvious. */
+ if (guard_tinfo.keyword == RID_DO
+ || guard_tinfo.keyword == RID_SWITCH)
return false;
/* If the token following the body is a close brace or an "else"
diff --git gcc/testsuite/c-c++-common/Wmisleading-indentation-4.c gcc/testsuite/c-c++-common/Wmisleading-indentation-4.c
index e69de29..d15a479 100644
--- gcc/testsuite/c-c++-common/Wmisleading-indentation-4.c
+++ gcc/testsuite/c-c++-common/Wmisleading-indentation-4.c
@@ -0,0 +1,11 @@
+/* PR c++/70639 */
+/* { dg-do compile } */
+/* { dg-options "-Wmisleading-indentation" } */
+
+void bar (int);
+void
+foo (int x)
+{
+ switch (x);
+ bar (x);
+}
Marek