From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6411 invoked by alias); 19 Dec 2008 23:32:28 -0000 Received: (qmail 6403 invoked by uid 22791); 19 Dec 2008 23:32:27 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,KAM_MX,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx2.redhat.com (HELO mx2.redhat.com) (66.187.237.31) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 19 Dec 2008 23:31:52 +0000 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id mBJNTot8023795; Fri, 19 Dec 2008 18:29:50 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id mBJNTnaK006921; Fri, 19 Dec 2008 18:29:50 -0500 Received: from [127.0.0.1] (sebastian-int.corp.redhat.com [172.16.52.221]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id mBJNTmQD009863; Fri, 19 Dec 2008 18:29:48 -0500 Message-ID: <494C2E6C.8090006@redhat.com> Date: Fri, 19 Dec 2008 23:50:00 -0000 From: Jason Merrill User-Agent: Thunderbird 2.0.0.18 (X11/20081119) MIME-Version: 1.0 To: Jakub Jelinek CC: =?ISO-8859-1?Q?Manuel_L=F3pez-Ib=E1=F1ez?= , Gcc Patch List , Mark Mitchell Subject: Re: PR c++/36921 [4.3/4.4 Regression] warning "comparison does not have mathematical meaning" is not correct for overloaded operators that do not return boolean References: <6c33472e0810250750y33c10265g3195e8613de1b1fc@mail.gmail.com> <20081025162735.GM14706@tyan-ft48-01.lab.bos.redhat.com> <6c33472e0811041414l57b4b98ibb84350dcf60117f@mail.gmail.com> <494C2488.7000002@redhat.com> <20081219231529.GK17496@tyan-ft48-01.lab.bos.redhat.com> In-Reply-To: <20081219231529.GK17496@tyan-ft48-01.lab.bos.redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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-12/txt/msg01084.txt.bz2 Jakub Jelinek wrote: > On Fri, Dec 19, 2008 at 05:47:36PM -0500, Jason Merrill wrote: >> I agree that we don't want to warn for this code, but I think the right >> place to fix it is in warn_about_parentheses; your patch will also >> disable the parenthesis warnings for overloaded comparison ops, which we >> don't want, since precedence is the same regardless of the return type. > > warn_about_parentheses isn't passed the whole expr though, so it can't check > its type. True, but that's not important. The interesting thing is the types of the arguments; we only want to warn if one of the arguments is a truthvalue. > when code has tcc_comparison class other than EQ_EXPR/NE_EXPR, > warning (OPT_Wparentheses, "comparisons like % do not " > "have their mathematical meaning"); > is the only thing warn_about_parentheses warns about. Ah, true. > We already have a precedent in build_x_binary_op for avoiding > warn_about_parentheses call in other situations, in particular about > obj << x + y. Yes, but that's because the C precedence of << seems natural for iostreams operations, whereas it can be confusing for arithmetic. Since, as you point out, we aren't actually missing any wanted warnings, I don't mind putting this logic in warn_about_parentheses. But the test should still check the types of the arguments rather than the whole expression. Mark: I understand your objection on the basis of user-defined Boolean types, but I think that the false positive rate for this warning for arbitrary overloads such as the PR submitter's is likely to outweigh the false negatives for Boolean classes. Jason