Add various new tests to Wmisleading-indentation.c:

  * Ensure that users can use pragma to turn off
    -Wmisleading-indentation for a range of code.

  * Add functions demonstrating a variety of indentation styles
    seen:

      (a) on http://en.wikipedia.org/wiki/Indent_style

      (b) via the manpage of GNU "indent"

    to verify that -Wmisleading-indentation doesn't emit false
    positives for these.

Tested with:

  make check-gcc RUNTESTFLAGS="-v -v dg.exp=Wmisleading-indentation.c"
  # of expected passes 42

  make check-g++ RUNTESTFLAGS="-v -v dg.exp=Wmisleading-indentation.c"
  # of expected passes          126

In both cases, the # of expected passes remained unchanged, and no new
fails were reported.

OK for trunk?

gcc/testsuite/ChangeLog:
        * c-c++-common/Wmisleading-indentation.c (fn_32): New.
        (fn_33_k_and_r_style): New.
        (fn_33_stroustrup_style): New.
        (fn_33_allman_style): New.
        (fn_33_whitesmiths_style): New.
        (fn_33_horstmann_style): New.
        (fn_33_ratliff_banner_style): New.
        (fn_33_lisp_style): New.
        (fn_34_indent_dash_gnu): New.
        (fn_34_indent_dash_kr): New.
        (fn_34_indent_dash_orig): New.
        (fn_34_indent_linux_style): New.
---
 .../c-c++-common/Wmisleading-indentation.c         | 224 +++++++++++++++++++++
 1 file changed, 224 insertions(+)

diff --git a/gcc/testsuite/c-c++-common/Wmisleading-indentation.c 
b/gcc/testsuite/c-c++-common/Wmisleading-indentation.c
index 3dbbb8b..6363d71 100644
--- a/gcc/testsuite/c-c++-common/Wmisleading-indentation.c
+++ b/gcc/testsuite/c-c++-common/Wmisleading-indentation.c
@@ -429,3 +429,227 @@ void fn_31 (void)
   else
     foo (3);
 }
+
+/* Ensure that we can disable the warning.  */
+int
+fn_32 (int flag)
+{
+  int x = 4, y = 5;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmisleading-indentation"
+  if (flag)
+    x = 3;
+    y = 2;
+#pragma GCC diagnostic pop
+
+  return x * y;
+}
+
+/* Verify that a variety of different indentation styles are supported
+   without leading to warnings.  */
+void
+fn_33_k_and_r_style (void)
+{
+  int i;
+  for (i = 0; i < 10; i++) {
+    if (flagB) {
+      foo(0);
+      foo(1);
+    } else {
+      foo(2);
+      foo(3);
+    }
+    foo(4);
+  }
+}
+
+void
+fn_33_stroustrup_style (void)
+{
+  int i;
+  for (i = 0; i < 10; i++) {
+    if (flagA) {
+      foo(0);
+      foo(1);
+    }
+    else {
+      foo(2);
+      foo(3);
+    }
+    foo(4);
+  }
+}
+
+void
+fn_33_allman_style (void)
+{
+  int i;
+  for (i = 0; i < 10; i++)
+  {
+    if (flagA)
+    {
+      foo(0);
+      foo(1);
+    }
+    else
+    {
+      foo(2);
+      foo(3);
+    }
+    foo(4);
+  }
+}
+
+void
+fn_33_whitesmiths_style (void)
+{
+    int i;
+    for (i = 0; i < 10; i++)
+        {
+        if (flagA)
+            {
+            foo(0);
+            foo(1);
+            }
+        else
+            {
+            foo(2);
+            foo(3);
+            }
+        foo(4);
+        }
+}
+
+void
+fn_33_horstmann_style (void)
+{
+    int i;
+    for (i = 0; i < 10; i++)
+    {   if (flagA)
+        {   foo(0);
+            foo(1);
+        }
+        else
+        {   foo(2);
+            foo(3);
+        }
+        foo(4);
+    }
+}
+
+void
+fn_33_ratliff_banner_style (void)
+{
+    int i;
+    for (i = 0; i < 10; i++) {
+       if (flagA) {
+           foo(0);
+           foo(1);
+           }
+       else {
+            foo(2);
+            foo(3);
+            }
+       foo(4);
+       }
+}
+
+void
+fn_33_lisp_style (void)
+{
+  int i;
+  for (i = 0; i < 10; i++) {
+    if (flagA) {
+        foo(0);
+        foo(1); }
+    else {
+        foo(2);
+        foo(3); }
+    foo(4); }
+}
+
+/* A function run through GNU "indent" with various options.
+   None of these should lead to warnings.  */
+
+/* "indent -gnu".  */
+void
+fn_34_indent_dash_gnu (void)
+{
+  int i;
+  while (flagA)
+    for (i = 0; i < 10; i++)
+      {
+       if (flagB)
+         {
+           foo (0);
+           foo (1);
+         }
+       else
+         {
+           foo (2);
+           foo (3);
+         }
+       foo (4);
+      }
+  foo (5);
+}
+
+/* "indent -kr".  */
+void fn_34_indent_dash_kr(void)
+{
+    int i;
+    while (flagA)
+       for (i = 0; i < 10; i++) {
+           if (flagB) {
+               foo(0);
+               foo(1);
+           } else {
+               foo(2);
+               foo(3);
+           }
+           foo(4);
+       }
+    foo(5);
+}
+
+/* "indent -orig".  */
+void
+fn_34_indent_dash_orig(void)
+{
+    int             i;
+    while (flagA)
+       for (i = 0; i < 10; i++) {
+           if (flagB) {
+               foo(0);
+               foo(1);
+           } else {
+               foo(2);
+               foo(3);
+           }
+           foo(4);
+       }
+    foo(5);
+}
+
+/* Linux style:
+   "indent \
+      -nbad -bap -nbc -bbo -hnl -br -brs -c33 -cd33 -ncdb -ce -ci4  \
+      -cli0 -d0 -di1 -nfc1 -i8 -ip0 -l80 -lp -npcs -nprs -npsl -sai \
+      -saf -saw -ncs -nsc -sob -nfca -cp33 -ss -ts8 -il1".  */
+
+void fn_34_indent_linux_style(void)
+{
+       int i;
+       while (flagA)
+               for (i = 0; i < 10; i++) {
+                       if (flagB) {
+                               foo(0);
+                               foo(1);
+                       } else {
+                               foo(2);
+                               foo(3);
+                       }
+                       foo(4);
+               }
+       foo(5);
+}
-- 
1.8.5.3

Reply via email to