From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29530 invoked by alias); 21 May 2008 16:13:18 -0000 Received: (qmail 29514 invoked by uid 22791); 21 May 2008 16:13:17 -0000 X-Spam-Check-By: sourceware.org Received: from ns.suse.de (HELO mx1.suse.de) (195.135.220.2) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 21 May 2008 16:12:57 +0000 Received: from Relay2.suse.de (mail2.suse.de [195.135.221.8]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.suse.de (Postfix) with ESMTP id 0F8F74171D for ; Wed, 21 May 2008 18:12:55 +0200 (CEST) Date: Wed, 21 May 2008 16:57:00 -0000 From: Michael Matz To: gcc-patches@gcc.gnu.org Subject: [patch] fix c++/27975, add new warning option -Wenum-compare Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2008-05/txt/msg01320.txt.bz2 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