This revision was automatically updated to reflect the committed changes.
Closed by commit rL298607: [clang-tidy] Catch trivially true statements like a 
!= 1 || a != 3 (authored by alexfh).

Changed prior to commit:
  https://reviews.llvm.org/D29858?vs=90087&id=92802#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29858

Files:
  clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/misc-redundant-expression.cpp


Index: clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -239,6 +239,11 @@
       (OpcodeRHS == BO_LT || OpcodeRHS == BO_LE))
     return true;
 
+  // Handle cases where constants are different but both ops are !=, like:
+  // x != 5 || x != 10
+  if (OpcodeLHS == BO_NE && OpcodeRHS == BO_NE)
+    return true;
+
   return false;
 }
 
Index: clang-tools-extra/trunk/test/clang-tidy/misc-redundant-expression.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-redundant-expression.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/misc-redundant-expression.cpp
@@ -321,6 +321,8 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: logical expression is always 
true
   if (X <= 10 || X >= 11) return 1;
   // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: logical expression is always 
true
+  if (X != 7 || X != 14) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: logical expression is always 
true
 
   if (X < 7 && X < 6) return 1;
   // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: expression is redundant
@@ -422,6 +424,8 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: logical expression is always 
false
   if (C == Red && C != Red) return 1;
   // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: logical expression is always 
false
+  if (C != Red || C != Yellow) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: logical expression is always 
true
 
   // Should not match.
   if (C == Red || C == Yellow) return 1;


Index: clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -239,6 +239,11 @@
       (OpcodeRHS == BO_LT || OpcodeRHS == BO_LE))
     return true;
 
+  // Handle cases where constants are different but both ops are !=, like:
+  // x != 5 || x != 10
+  if (OpcodeLHS == BO_NE && OpcodeRHS == BO_NE)
+    return true;
+
   return false;
 }
 
Index: clang-tools-extra/trunk/test/clang-tidy/misc-redundant-expression.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-redundant-expression.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/misc-redundant-expression.cpp
@@ -321,6 +321,8 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: logical expression is always true
   if (X <= 10 || X >= 11) return 1;
   // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: logical expression is always true
+  if (X != 7 || X != 14) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: logical expression is always true
 
   if (X < 7 && X < 6) return 1;
   // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: expression is redundant
@@ -422,6 +424,8 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: logical expression is always false
   if (C == Red && C != Red) return 1;
   // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: logical expression is always false
+  if (C != Red || C != Yellow) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: logical expression is always true
 
   // Should not match.
   if (C == Red || C == Yellow) return 1;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to