OSDN Git Service

Fix c++/27975.
authormatz <matz@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 27 May 2008 14:59:53 +0000 (14:59 +0000)
committermatz <matz@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 27 May 2008 14:59:53 +0000 (14:59 +0000)
        * c.opt (Wenum-compare): New warning option.
        * doc/invoke.texi (Warning Options): Document -Wenum-compare.

cp/
        * call.c (build_new_op): Make warning conditional on OPT_Wenum_compare.

testsuite/
        * g++.dg/warn/Wenum-compare.C: New testcase.
        * g++.dg/warn/Wenum-compare-no.C: Ditto.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@136035 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c.opt
gcc/cp/ChangeLog
gcc/cp/call.c
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wenum-compare-no.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/Wenum-compare.C [new file with mode: 0644]

index 33ef156..60a0c8c 100644 (file)
@@ -1,5 +1,11 @@
 2008-05-27  Michael Matz  <matz@suse.de>
 
+       PR c++/27975
+       * c.opt (Wenum-compare): New warning option.
+       * doc/invoke.texi  (Warning Options): Document -Wenum-compare.
+
+2008-05-27  Michael Matz  <matz@suse.de>
+
        PR middle-end/36326
        * tree-gimple.c (is_gimple_mem_rhs): Remove work-around for
        non-BLKmode types.
index 18ce852..9669f2c 100644 (file)
--- a/gcc/c.opt
+++ b/gcc/c.opt
@@ -195,6 +195,10 @@ Wendif-labels
 C ObjC C++ ObjC++ Warning
 Warn about stray tokens after #elif and #endif
 
+Wenum-compare
+C++ ObjC++ Var(warn_enum_compare) Init(1) Warning
+Warn about comparison of different enum types
+
 Werror
 C ObjC C++ ObjC++
 ; Documented in common.opt
index 3c54503..f371d8c 100644 (file)
@@ -1,3 +1,9 @@
+2008-05-27  Michael Matz  <matz@suse.de>
+
+       PR c++/27975
+       * call.c (build_new_op): Make warning conditional on
+       OPT_Wenum_compare.
+
 2008-05-27  Alexandre Oliva  <aoliva@redhat.com>
 
        PR c++/35909
index fe78f9c..0948c79 100644 (file)
@@ -4004,7 +4004,8 @@ build_new_op (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3,
                      != TYPE_MAIN_VARIANT (TREE_TYPE (arg2)))
                  && (complain & tf_warning))
                {
-                 warning (0, "comparison between %q#T and %q#T",
+                 warning (OPT_Wenum_compare,
+                          "comparison between %q#T and %q#T",
                           TREE_TYPE (arg1), TREE_TYPE (arg2));
                }
              break;
index e367817..a2665f3 100644 (file)
@@ -232,7 +232,7 @@ Objective-C and Objective-C++ Dialects}.
 -Wchar-subscripts -Wclobbered  -Wcomment @gol
 -Wconversion  -Wcoverage-mismatch  -Wno-deprecated  @gol
 -Wno-deprecated-declarations -Wdisabled-optimization  -Wno-div-by-zero  @gol
--Wempty-body  -Wno-endif-labels @gol
+-Wempty-body  -Wenum-compare -Wno-endif-labels @gol
 -Werror  -Werror=* @gol
 -Wfatal-errors  -Wfloat-equal  -Wformat  -Wformat=2 @gol
 -Wno-format-contains-nul -Wno-format-extra-args -Wformat-nonliteral @gol
@@ -3658,6 +3658,11 @@ while} statement.  Additionally, in C++, warn when an empty body occurs
 in a @samp{while} or @samp{for} statement with no whitespacing before
 the semicolon.  This warning is also enabled by @option{-Wextra}.
 
+@item -Wenum-compare @r{(C++ and Objective-C++ only)}
+@opindex Wenum-compare
+@opindex Wno-enum-compare
+Warn about a comparison between values of different enum types.
+
 @item -Wsign-compare
 @opindex Wsign-compare
 @opindex Wno-sign-compare
index 815ab8a..ec36b2c 100644 (file)
@@ -1,3 +1,9 @@
+2008-05-27  Michael Matz  <matz@suse.de>
+
+       PR c++/27975
+       * g++.dg/warn/Wenum-compare.C: New testcase.
+       * g++.dg/warn/Wenum-compare-no.C: Ditto.
+
 2008-05-27  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/36339
diff --git a/gcc/testsuite/g++.dg/warn/Wenum-compare-no.C b/gcc/testsuite/g++.dg/warn/Wenum-compare-no.C
new file mode 100644 (file)
index 0000000..7dc27d3
--- /dev/null
@@ -0,0 +1,10 @@
+/* Test disabling -Wenum-compare (on by default).  See PR27975.  */
+/* { dg-do compile } */
+/* { dg-options "-Wno-enum-compare" } */
+enum E1 { a };
+enum E2 { b };
+
+int foo (E1 e1, E2 e2)
+{
+  return e1 == e2;  /* { dg-bogus "comparison between" } */
+}
diff --git a/gcc/testsuite/g++.dg/warn/Wenum-compare.C b/gcc/testsuite/g++.dg/warn/Wenum-compare.C
new file mode 100644 (file)
index 0000000..f600800
--- /dev/null
@@ -0,0 +1,10 @@
+/* Test that we get the -Wenum-compare by default.  See PR27975.  */
+/* { dg-do compile } */
+/* { dg-options "" } */
+enum E1 { a };
+enum E2 { b };
+
+int foo (E1 e1, E2 e2)
+{
+  return e1 == e2;  /* { dg-warning "comparison between" } */
+}