This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] fix c++/27975, add new warning option -Wenum-compare
- From: Michael Matz <matz at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 21 May 2008 18:12:54 +0200 (CEST)
- Subject: [patch] fix c++/27975, add new warning option -Wenum-compare
Hi,
the bugreport asks for the possibility to disable the warning about
comparison of values of different enum types. The request seems
reasonable and I've put it under the control of a new flag -Wenum-compare
(only for C++ as only that frontend implements the warning).
Right now it's disabled by default, but we could enable it with -Wall or
-Wextra, I'll do whatever is decided.
Regstrapping in progress, okay for trunk if that passes?
Ciao,
Michael.
Fix c++/27975.
* c.opt (Wenum-compare): New warning option.
cp/
* call.c (build_new_op): Make warning conditional on OPT_Wenum_compare.
doc/
* invoke.texi (Warning Options): Document -Wenum-compare.
Index: gcc/c.opt
===================================================================
--- gcc/c.opt (revision 135599)
+++ gcc/c.opt (working copy)
@@ -195,6 +195,10 @@ Wendif-labels
C ObjC C++ ObjC++ Warning
Warn about stray tokens after #elif and #endif
+Wenum-compare
+C++ ObjC++ Warning
+Warn about comparison of different enum types
+
Werror
C ObjC C++ ObjC++
; Documented in common.opt
Index: gcc/cp/call.c
===================================================================
*** gcc/cp/call.c (revision 135599)
--- gcc/cp/call.c (working copy)
*************** build_new_op (enum tree_code code, int f
*** 4004,4010 ****
!= TYPE_MAIN_VARIANT (TREE_TYPE (arg2)))
&& (complain & tf_warning))
{
! warning (0, "comparison between %q#T and %q#T",
TREE_TYPE (arg1), TREE_TYPE (arg2));
}
break;
--- 4004,4011 ----
!= TYPE_MAIN_VARIANT (TREE_TYPE (arg2)))
&& (complain & tf_warning))
{
! warning (OPT_Wenum_compare,
! "comparison between %q#T and %q#T",
TREE_TYPE (arg1), TREE_TYPE (arg2));
}
break;
Index: gcc/doc/invoke.texi
===================================================================
--- gcc/doc/invoke.texi (revision 135599)
+++ gcc/doc/invoke.texi (working copy)
@@ -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
@@ -3663,6 +3664,11 @@ while} statement. Additionally, in C++,
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