This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH for c++/70639 (ICE-on-valid with -Wmisleading-indentation and switch)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]