This is the mail archive of the 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]

unused comparison warning (bug 62182)


I've submitted a patch to bug 62182 [1], and I would like to have some
feedback about it (this is still WIP as noted in the bug).
As it is my first patch to gcc, I'm not sure what is the best way to
discuss/review patches (here or in bugzilla).
Anyway, please let me know your thoughts :)


Index: gcc/c/c-typeck.c
--- gcc/c/c-typeck.c	(rÃvision 221845)
+++ gcc/c/c-typeck.c	(copie de travail)
@@ -9921,6 +9921,10 @@ emit_side_effect_warnings (location_t lo
   if (expr == error_mark_node)
+  else if (TREE_CODE (expr) == EQ_EXPR && !VOID_TYPE_P (TREE_TYPE (expr)) && !TREE_NO_WARNING (expr))
+    {
+      warning_at (loc, OPT_Wunused_comparison, "equality comparison result unused: did you mean '='?");
+    }
   else if (!TREE_SIDE_EFFECTS (expr))
       if (!VOID_TYPE_P (TREE_TYPE (expr)) && !TREE_NO_WARNING (expr))
Index: gcc/common.opt
--- gcc/common.opt	(rÃvision 221845)
+++ gcc/common.opt	(copie de travail)
@@ -727,6 +727,10 @@ Wunused-variable
 Common Var(warn_unused_variable) Warning EnabledBy(Wunused)
 Warn when a variable is unused
+Common Var(warn_unused_comparison) Warning EnabledBy(Wunused)
+Warn when the result of a comparison is unused
 Common Var(warn_coverage_mismatch) Init(1) Warning
 Warn in case profiles in -fprofile-use do not match
Index: gcc/cp/cvt.c
--- gcc/cp/cvt.c	(rÃvision 221845)
+++ gcc/cp/cvt.c	(copie de travail)
@@ -1345,9 +1345,15 @@ convert_to_void (tree expr, impl_conv_vo
 	  && !TREE_NO_WARNING (expr)
 	  && !processing_template_decl)
+    if ((TREE_CODE (expr) == EQ_EXPR) && !TREE_NO_WARNING (expr))
+      {
+        warning_at (loc, OPT_Wunused_comparison,
+        "equality comparison result unused: "
+        "did you mean '='?");
+      }
 	  /* The middle end does not warn about expressions that have
 	     been explicitly cast to void, so we must do so here.  */
-	  if (!TREE_SIDE_EFFECTS (expr)) {
+    else if (!TREE_SIDE_EFFECTS (expr)) {
             if (complain & tf_warning)
 	      switch (implicit)
Index: gcc/doc/invoke.texi
--- gcc/doc/invoke.texi	(rÃvision 221845)
+++ gcc/doc/invoke.texi	(copie de travail)
@@ -285,7 +285,7 @@ Objective-C and Objective-C++ Dialects}.
 -Wunsuffixed-float-constants  -Wunused  -Wunused-function @gol
 -Wunused-label  -Wunused-local-typedefs -Wunused-parameter @gol
 -Wno-unused-result -Wunused-value @gol -Wunused-variable @gol
--Wunused-but-set-parameter -Wunused-but-set-variable @gol
+-Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-comparison @gol
 -Wuseless-cast -Wvariadic-macros -Wvector-operation-performance @gol
 -Wvla -Wvolatile-register-var  -Wwrite-strings @gol

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