r179740 - Update the -Wparentheses tests to check that fix-its are in the correct place.

Richard Trieu rtrieu at google.com
Wed Apr 17 17:56:24 PDT 2013


Author: rtrieu
Date: Wed Apr 17 19:56:23 2013
New Revision: 179740

URL: http://llvm.org/viewvc/llvm-project?rev=179740&view=rev
Log:
Update the -Wparentheses tests to check that fix-its are in the correct place.

Modified:
    cfe/trunk/test/Sema/parentheses.c
    cfe/trunk/test/Sema/parentheses.cpp

Modified: cfe/trunk/test/Sema/parentheses.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/parentheses.c?rev=179740&r1=179739&r2=179740&view=diff
==============================================================================
--- cfe/trunk/test/Sema/parentheses.c (original)
+++ cfe/trunk/test/Sema/parentheses.c Wed Apr 17 19:56:23 2013
@@ -1,24 +1,44 @@
 // RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify %s
+// RUN: %clang_cc1 -Wparentheses -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
 
 // Test the various warnings under -Wparentheses
 void if_assign(void) {
   int i;
   if (i = 4) {} // expected-warning {{assignment as a condition}} \
-                // expected-note{{use '==' to turn this assignment into an equality comparison}} \
-  // expected-note{{place parentheses around the assignment to silence this warning}}
+                // expected-note{{place parentheses around the assignment to silence this warning}} \
+                // expected-note{{use '==' to turn this assignment into an equality comparison}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:7-[[@LINE-3]]:7}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:12-[[@LINE-4]]:12}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:9-[[@LINE-5]]:10}:"=="
+
   if ((i = 4)) {}
 }
 
 void bitwise_rel(unsigned i) {
   (void)(i & 0x2 == 0); // expected-warning {{& has lower precedence than ==}} \
-                        // expected-note{{place parentheses around the & expression to evaluate it first}} \
-  // expected-note{{place parentheses around the '==' expression to silence this warning}}
+                        // expected-note{{place parentheses around the '==' expression to silence this warning}} \
+                        // expected-note{{place parentheses around the & expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:14-[[@LINE-3]]:14}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:22-[[@LINE-4]]:22}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:10-[[@LINE-5]]:10}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:17-[[@LINE-6]]:17}:")"
+
   (void)(0 == i & 0x2); // expected-warning {{& has lower precedence than ==}} \
-                        // expected-note{{place parentheses around the & expression to evaluate it first}} \
-  // expected-note{{place parentheses around the '==' expression to silence this warning}}
+                        // expected-note{{place parentheses around the '==' expression to silence this warning}} \
+                        // expected-note{{place parentheses around the & expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:10}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:16-[[@LINE-4]]:16}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:15-[[@LINE-5]]:15}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:22-[[@LINE-6]]:22}:")"
+
   (void)(i & 0xff < 30); // expected-warning {{& has lower precedence than <}} \
-                        // expected-note{{place parentheses around the & expression to evaluate it first}} \
-  // expected-note{{place parentheses around the '<' expression to silence this warning}}
+                         // expected-note{{place parentheses around the '<' expression to silence this warning}} \
+                         // expected-note{{place parentheses around the & expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:14-[[@LINE-3]]:14}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:23-[[@LINE-4]]:23}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:10-[[@LINE-5]]:10}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:18-[[@LINE-6]]:18}:")"
+
   (void)((i & 0x2) == 0);
   (void)(i & (0x2 == 0));
   // Eager logical op
@@ -27,19 +47,33 @@ void bitwise_rel(unsigned i) {
 
   (void)(i & i | i); // expected-warning {{'&' within '|'}} \
                      // expected-note {{place parentheses around the '&' expression to silence this warning}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:10-[[@LINE-2]]:10}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:15-[[@LINE-3]]:15}:")"
 
   (void)(i | i & i); // expected-warning {{'&' within '|'}} \
                      // expected-note {{place parentheses around the '&' expression to silence this warning}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:14-[[@LINE-2]]:14}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:19-[[@LINE-3]]:19}:")"
 
   (void)(i ||
              i && i); // expected-warning {{'&&' within '||'}} \
-                       // expected-note {{place parentheses around the '&&' expression to silence this warning}}
+                      // expected-note {{place parentheses around the '&&' expression to silence this warning}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:14-[[@LINE-2]]:14}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:20-[[@LINE-3]]:20}:")"
+
   (void)(i || i && "w00t"); // no warning.
   (void)("w00t" && i || i); // no warning.
+
   (void)(i || i && "w00t" || i); // expected-warning {{'&&' within '||'}} \
                                  // expected-note {{place parentheses around the '&&' expression to silence this warning}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:15-[[@LINE-2]]:15}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:26-[[@LINE-3]]:26}:")"
+
   (void)(i || "w00t" && i || i); // expected-warning {{'&&' within '||'}} \
                                  // expected-note {{place parentheses around the '&&' expression to silence this warning}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:15-[[@LINE-2]]:15}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:26-[[@LINE-3]]:26}:")"
+
   (void)(i && i || 0); // no warning.
   (void)(0 || i && i); // no warning.
 }
@@ -48,25 +82,41 @@ _Bool someConditionFunc();
 
 void conditional_op(int x, int y, _Bool b) {
   (void)(x + someConditionFunc() ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '+'}} \
-                                           // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
-                                           // expected-note {{place parentheses around the '+' expression to silence this warning}}
+                                           // expected-note {{place parentheses around the '+' expression to silence this warning}} \
+                                           // expected-note {{place parentheses around the '?:' expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:10}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:33-[[@LINE-4]]:33}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:14-[[@LINE-5]]:14}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:41-[[@LINE-6]]:41}:")"
 
   (void)((x + someConditionFunc()) ? 1 : 2); // no warning
 
   (void)(x - b ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '-'}} \
-                         // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
-                         // expected-note {{place parentheses around the '-' expression to silence this warning}}
+                         // expected-note {{place parentheses around the '-' expression to silence this warning}} \
+                         // expected-note {{place parentheses around the '?:' expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:10}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:15-[[@LINE-4]]:15}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:14-[[@LINE-5]]:14}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:23-[[@LINE-6]]:23}:")"
 
   (void)(x * (x == y) ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '*'}} \
-                                // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
-                                // expected-note {{place parentheses around the '*' expression to silence this warning}}
+                                // expected-note {{place parentheses around the '*' expression to silence this warning}} \
+                                // expected-note {{place parentheses around the '?:' expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:10}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:22-[[@LINE-4]]:22}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:14-[[@LINE-5]]:14}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:30-[[@LINE-6]]:30}:")"
 
   (void)(x / !x ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '/'}} \
-                          // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
-                          // expected-note {{place parentheses around the '/' expression to silence this warning}}
+                          // expected-note {{place parentheses around the '/' expression to silence this warning}} \
+                          // expected-note {{place parentheses around the '?:' expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:10}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:16-[[@LINE-4]]:16}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:14-[[@LINE-5]]:14}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:24-[[@LINE-6]]:24}:")"
 
   (void)(x % 2 ? 1 : 2); // no warning
 }
 
-// RUN: %clang_cc1 -fsyntax-only -Wparentheses -Werror -fdiagnostics-show-option %s 2>&1 | FileCheck %s
-// CHECK: error: using the result of an assignment as a condition without parentheses [-Werror,-Wparentheses]
+// RUN: %clang_cc1 -fsyntax-only -Wparentheses -Werror -fdiagnostics-show-option %s 2>&1 | FileCheck %s -check-prefix=CHECK-FLAG
+// CHECK-FLAG: error: using the result of an assignment as a condition without parentheses [-Werror,-Wparentheses]

Modified: cfe/trunk/test/Sema/parentheses.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/parentheses.cpp?rev=179740&r1=179739&r2=179740&view=diff
==============================================================================
--- cfe/trunk/test/Sema/parentheses.cpp (original)
+++ cfe/trunk/test/Sema/parentheses.cpp Wed Apr 17 19:56:23 2013
@@ -1,19 +1,32 @@
 // RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify %s
+// RUN: %clang_cc1 -Wparentheses -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
 
 bool someConditionFunc();
 
 void conditional_op(int x, int y, bool b) {
   (void)(x + someConditionFunc() ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '+'}} \
-                                           // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
-                                           // expected-note {{place parentheses around the '+' expression to silence this warning}}
+                                           // expected-note {{place parentheses around the '+' expression to silence this warning}} \
+                                           // expected-note {{place parentheses around the '?:' expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:10}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:33-[[@LINE-4]]:33}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:14-[[@LINE-5]]:14}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:41-[[@LINE-6]]:41}:")"
 
   (void)(x - b ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '-'}} \
-                         // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
-                         // expected-note {{place parentheses around the '-' expression to silence this warning}}
+                         // expected-note {{place parentheses around the '-' expression to silence this warning}} \
+                         // expected-note {{place parentheses around the '?:' expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:10}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:15-[[@LINE-4]]:15}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:14-[[@LINE-5]]:14}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:23-[[@LINE-6]]:23}:")"
 
   (void)(x * (x == y) ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '*'}} \
-                                // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
-                                // expected-note {{place parentheses around the '*' expression to silence this warning}}
+                                // expected-note {{place parentheses around the '*' expression to silence this warning}} \
+                                // expected-note {{place parentheses around the '?:' expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:10}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:22-[[@LINE-4]]:22}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:14-[[@LINE-5]]:14}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:30-[[@LINE-6]]:30}:")"
 }
 
 class Stream {
@@ -27,14 +40,24 @@ public:
 
 void f(Stream& s, bool b) {
   (void)(s << b ? "foo" : "bar"); // expected-warning {{operator '?:' has lower precedence than '<<'}} \
-                                  // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
-                                  // expected-note {{place parentheses around the '<<' expression to silence this warning}}
+                                  // expected-note {{place parentheses around the '<<' expression to silence this warning}} \
+                                  // expected-note {{place parentheses around the '?:' expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:10}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:16-[[@LINE-4]]:16}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:15-[[@LINE-5]]:15}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:32-[[@LINE-6]]:32}:")"
+
   (void)(s << 5 == 1); // expected-warning {{overloaded operator << has lower precedence than comparison operator}} \
-                       // expected-note {{place parentheses around the '<<' expression to silence this warning}} \
-                       // expected-note {{place parentheses around comparison expression to evaluate it first}}
+                       // expected-note {{place parentheses around comparison expression to evaluate it first}} \
+                       // expected-note {{place parentheses around the '<<' expression to silence this warning}}
+
   (void)(s >> 5 == 1); // expected-warning {{overloaded operator >> has lower precedence than comparison operator}} \
-                       // expected-note {{place parentheses around the '>>' expression to silence this warning}} \
-                       // expected-note {{place parentheses around comparison expression to evaluate it first}}
+                       // expected-note {{place parentheses around comparison expression to evaluate it first}} \
+                       // expected-note {{place parentheses around the '>>' expression to silence this warning}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:15-[[@LINE-3]]:15}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:21-[[@LINE-4]]:21}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:10-[[@LINE-5]]:10}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:16-[[@LINE-6]]:16}:")"
 }
 
 struct S {
@@ -44,8 +67,12 @@ struct S {
 
 void test(S *s, bool (S::*m_ptr)()) {
   (void)(*s + true ? "foo" : "bar"); // expected-warning {{operator '?:' has lower precedence than '+'}} \
-                                     // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
-                                     // expected-note {{place parentheses around the '+' expression to silence this warning}}
+                                     // expected-note {{place parentheses around the '+' expression to silence this warning}} \
+                                     // expected-note {{place parentheses around the '?:' expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:10}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:19-[[@LINE-4]]:19}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:15-[[@LINE-5]]:15}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:35-[[@LINE-6]]:35}:")"
 
   (void)((*s + true) ? "foo" : "bar"); // No warning.
 
@@ -56,11 +83,19 @@ void test(S *s, bool (S::*m_ptr)()) {
 void test(int a, int b, int c) {
   (void)(a >> b + c); // expected-warning {{operator '>>' has lower precedence than '+'; '+' will be evaluated first}} \
                          expected-note {{place parentheses around the '+' expression to silence this warning}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:15-[[@LINE-2]]:15}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:20-[[@LINE-3]]:20}:")"
+
   (void)(a - b << c); // expected-warning {{operator '<<' has lower precedence than '-'; '-' will be evaluated first}} \
                          expected-note {{place parentheses around the '-' expression to silence this warning}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:10-[[@LINE-2]]:10}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:15-[[@LINE-3]]:15}:")"
+
   Stream() << b + c;
   Stream() >> b + c; // expected-warning {{operator '>>' has lower precedence than '+'; '+' will be evaluated first}} \
                         expected-note {{place parentheses around the '+' expression to silence this warning}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:15-[[@LINE-2]]:15}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:20-[[@LINE-3]]:20}:")"
 }
 
 namespace PR15628 {





More information about the cfe-commits mailing list