From patchwork Thu May 31 10:43:47 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 162135 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 99B02B7002 for ; Thu, 31 May 2012 20:45:38 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1339065943; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Message-ID:Date:From:User-Agent:MIME-Version: To:CC:Subject:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=MEkiH/dReTeA8b3EhbOgr1/WcRg=; b=aT/xGin+DZmQBjQ xYH7OW2nuguywUQgRduTQSTSmvOGVl4iflIk3nfVy6cqGqQ8hUnVf5ug24mrAX7H vJaaHZIVep1G+jiOMDAEhYczj0J7+gB35pCYxrHYXfooMlA0FUN84fCaLs1c2nE7 CkpM6zBnrawW/ev+gt3ADgrxq8bg= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=wwnt2U2MFkK9TrFJPvLfexDnlvx6o1USdlrhy6LKQTSFudv9xqowm/ie3a4Wzw 1mjC1goyWqTifVRDIUVnkFdNgnZGUN7lzitzhywJH8zh8JiDFPeOxNE7tltla4GV S+E4owu0AXPEV1aAp0nW/NZqDBFqpw3dUsTdRcE/ylLzA=; Received: (qmail 1218 invoked by alias); 31 May 2012 10:45:30 -0000 Received: (qmail 1199 invoked by uid 22791); 31 May 2012 10:45:27 -0000 X-SWARE-Spam-Status: No, hits=-6.6 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_W, TW_PM, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from acsinet15.oracle.com (HELO acsinet15.oracle.com) (141.146.126.227) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 31 May 2012 10:45:13 +0000 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by acsinet15.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id q4VAjAdk024844 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 31 May 2012 10:45:11 GMT Received: from acsmt358.oracle.com (acsmt358.oracle.com [141.146.40.158]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id q4VAjAwU007957 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 31 May 2012 10:45:10 GMT Received: from abhmt106.oracle.com (abhmt106.oracle.com [141.146.116.58]) by acsmt358.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id q4VAjAe7021078; Thu, 31 May 2012 05:45:10 -0500 Received: from [192.168.1.4] (/79.53.13.118) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 31 May 2012 03:45:09 -0700 Message-ID: <4FC74B63.3020005@oracle.com> Date: Thu, 31 May 2012 12:43:47 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120421 Thunderbird/12.0 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch] PR 53524 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi, when I fixed PR16603 (for 4.7.0) I didn't anticipate that we would warn more easily about mismatching enum types for user code using conditional expressions to define enumerators basing on other enumerators of the same open enum, like the testcase in this PR shows. Generally speaking, IMHO the warning is a bit pedantic, eg, the EDG front-end doesn't warn at all, thus it seems to me that a good thing to do, safe for 4.7.1 too, is giving the warning a unique name and moving it to -Wall. Bootstrapped and tested x86_64-linux. Thanks, Paolo. //////////////////////////// 2012-05-31 Paolo Carlini PR c++/53524 * doc/invoke.texi (Wenum-mismatch): Document. /cp 2012-05-31 Paolo Carlini PR c++/53524 * call.c (build_conditional_expr_1): Use OPT_Wenum_mismatch. /c-family 2012-05-31 Paolo Carlini PR c++/53524 * c.opt (Wenum-mismatch): Add. /testsuite 2012-05-31 Paolo Carlini PR c++/53524 * g++.dg/warn/Wenum-mismatch1.C: New. * g++.dg/warn/Wenum-mismatch2.C: Likewise. * g++.dg/warn/Wenum-mismatch3.C: Likewise. * g++.old-deja/g++.other/cond5.C: Adjust. Index: doc/invoke.texi =================================================================== --- doc/invoke.texi (revision 188050) +++ doc/invoke.texi (working copy) @@ -198,8 +198,8 @@ in the following sections. -fno-default-inline -fvisibility-inlines-hidden @gol -fvisibility-ms-compat @gol -Wabi -Wconversion-null -Wctor-dtor-privacy @gol --Wdelete-non-virtual-dtor -Wliteral-suffix -Wnarrowing @gol --Wnoexcept -Wnon-virtual-dtor -Wreorder @gol +-Wdelete-non-virtual-dtor -Wenum-mismatch -Wliteral-suffix @gol +-Wnarrowing -Wnoexcept -Wnon-virtual-dtor -Wreorder @gol -Weffc++ -Wstrict-null-sentinel @gol -Wno-non-template-friend -Wold-style-cast @gol -Woverloaded-virtual -Wno-pmf-conversions @gol @@ -3084,6 +3084,7 @@ Options} and @ref{Objective-C and Objective-C++ Di -Wc++11-compat @gol -Wchar-subscripts @gol -Wenum-compare @r{(in C/Objc; this is on by default in C++)} @gol +-Wenum-mismatch @r{(in C++)} @gol -Wimplicit-int @r{(C and Objective-C only)} @gol -Wimplicit-function-declaration @r{(C and Objective-C only)} @gol -Wcomment @gol @@ -4301,6 +4302,12 @@ Warn about a comparison between values of differen this warning is enabled by default. In C this warning is enabled by @option{-Wall}. +@item -Wenum-mismatch @r{(C++ and Objective-C++ only)} +@opindex Wenum-mismatch +@opindex Wno-enum-mismatch +Warn about values of different enumerated types in conditional +expressions. This warning is enabled by @option{-Wall}. + @item -Wjump-misses-init @r{(C, Objective-C only)} @opindex Wjump-misses-init @opindex Wno-jump-misses-init Index: c-family/c.opt =================================================================== --- c-family/c.opt (revision 188053) +++ c-family/c.opt (working copy) @@ -360,6 +360,10 @@ Wenum-compare C ObjC C++ ObjC++ Var(warn_enum_compare) Init(-1) Warning Warn about comparison of different enum types +Wenum-mismatch +C++ ObjC++ Var(warn_enum_mismatch) Warning LangEnabledBy(C++ ObjC++,Wall) +Warn about enumeral mismatch in conditional expression + Werror C ObjC C++ ObjC++ ; Documented in common.opt Index: testsuite/g++.old-deja/g++.other/cond5.C =================================================================== --- testsuite/g++.old-deja/g++.other/cond5.C (revision 188050) +++ testsuite/g++.old-deja/g++.other/cond5.C (working copy) @@ -1,7 +1,7 @@ // { dg-do assemble } -// { dg-options "-W -pedantic -ansi" } +// { dg-options "-W -Wenum-mismatch -pedantic -ansi" } -// Copyright (C) 1999, 2000 Free Software Foundation, Inc. +// Copyright (C) 1999, 2000, 2012 Free Software Foundation, Inc. // Contributed by Nathan Sidwell 1 Sep 1999 // Derived from bug report from Gabriel Dos Reis // Index: testsuite/g++.dg/warn/Wenum-mismatch1.C =================================================================== --- testsuite/g++.dg/warn/Wenum-mismatch1.C (revision 0) +++ testsuite/g++.dg/warn/Wenum-mismatch1.C (revision 0) @@ -0,0 +1,30 @@ +// PR c++/53524 + +template < typename > struct PointerLikeTypeTraits { + enum { NumLowBitsAvailable }; +}; + +class CodeGenInstruction; +class CodeGenInstAlias; + +template < typename T> +struct PointerIntPair { + enum { IntShift = T::NumLowBitsAvailable }; +}; + +template < typename PT1, typename PT2 > struct PointerUnionUIntTraits { + enum { + PT1BitsAv = PointerLikeTypeTraits < PT1 >::NumLowBitsAvailable, + PT2BitsAv = PointerLikeTypeTraits < PT2 >::NumLowBitsAvailable, + NumLowBitsAvailable = 0 ? PT1BitsAv : PT2BitsAv + }; +}; + +template < typename PT1, typename PT2 > class PointerUnion { + typedef PointerIntPair < PointerUnionUIntTraits < PT1, PT2 > > ValTy; + ValTy Val; +}; + +struct ClassInfo { + PointerUnion < CodeGenInstruction *, CodeGenInstAlias * > DefRec; +}; Index: testsuite/g++.dg/warn/Wenum-mismatch2.C =================================================================== --- testsuite/g++.dg/warn/Wenum-mismatch2.C (revision 0) +++ testsuite/g++.dg/warn/Wenum-mismatch2.C (revision 0) @@ -0,0 +1,31 @@ +// PR c++/53524 +// { dg-options "-Wenum-mismatch" } + +template < typename > struct PointerLikeTypeTraits { + enum { NumLowBitsAvailable }; +}; + +class CodeGenInstruction; +class CodeGenInstAlias; + +template < typename T> +struct PointerIntPair { + enum { IntShift = T::NumLowBitsAvailable }; +}; + +template < typename PT1, typename PT2 > struct PointerUnionUIntTraits { + enum { + PT1BitsAv = PointerLikeTypeTraits < PT1 >::NumLowBitsAvailable, + PT2BitsAv = PointerLikeTypeTraits < PT2 >::NumLowBitsAvailable, + NumLowBitsAvailable = 0 ? PT1BitsAv : PT2BitsAv // { dg-warning "enumeral mismatch" } + }; +}; + +template < typename PT1, typename PT2 > class PointerUnion { + typedef PointerIntPair < PointerUnionUIntTraits < PT1, PT2 > > ValTy; + ValTy Val; +}; + +struct ClassInfo { + PointerUnion < CodeGenInstruction *, CodeGenInstAlias * > DefRec; +}; Index: testsuite/g++.dg/warn/Wenum-mismatch3.C =================================================================== --- testsuite/g++.dg/warn/Wenum-mismatch3.C (revision 0) +++ testsuite/g++.dg/warn/Wenum-mismatch3.C (revision 0) @@ -0,0 +1,31 @@ +// PR c++/53524 +// { dg-options "-Wall" } + +template < typename > struct PointerLikeTypeTraits { + enum { NumLowBitsAvailable }; +}; + +class CodeGenInstruction; +class CodeGenInstAlias; + +template < typename T> +struct PointerIntPair { + enum { IntShift = T::NumLowBitsAvailable }; +}; + +template < typename PT1, typename PT2 > struct PointerUnionUIntTraits { + enum { + PT1BitsAv = PointerLikeTypeTraits < PT1 >::NumLowBitsAvailable, + PT2BitsAv = PointerLikeTypeTraits < PT2 >::NumLowBitsAvailable, + NumLowBitsAvailable = 0 ? PT1BitsAv : PT2BitsAv // { dg-warning "enumeral mismatch" } + }; +}; + +template < typename PT1, typename PT2 > class PointerUnion { + typedef PointerIntPair < PointerUnionUIntTraits < PT1, PT2 > > ValTy; + ValTy Val; +}; + +struct ClassInfo { + PointerUnion < CodeGenInstruction *, CodeGenInstAlias * > DefRec; +}; Index: cp/call.c =================================================================== --- cp/call.c (revision 188053) +++ cp/call.c (working copy) @@ -4697,7 +4697,7 @@ build_conditional_expr_1 (tree arg1, tree arg2, tr && TREE_CODE (arg3_type) == ENUMERAL_TYPE) { if (complain & tf_warning) - warning (0, + warning (OPT_Wenum_mismatch, "enumeral mismatch in conditional expression: %qT vs %qT", arg2_type, arg3_type); }