From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16364 invoked by alias); 19 Dec 2008 23:50:03 -0000 Received: (qmail 16309 invoked by uid 22791); 19 Dec 2008 23:50:01 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00,KAM_MX,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 19 Dec 2008 23:49:26 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id mBJNlNdL016078; Fri, 19 Dec 2008 18:47:23 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id mBJNlLiF024074; Fri, 19 Dec 2008 18:47:21 -0500 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.2/8.14.2/Submit) id mBJNlK6q019373; Sat, 20 Dec 2008 00:47:20 +0100 Date: Sat, 20 Dec 2008 00:17:00 -0000 From: Jakub Jelinek To: Jason Merrill Cc: Manuel =?iso-8859-1?B?TPNwZXotSWLh8WV6?= , 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 Message-ID: <20081219234720.GL17496@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek 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> <494C2E6C.8090006@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <494C2E6C.8090006@redhat.com> User-Agent: Mutt/1.5.18 (2008-05-17) 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-12/txt/msg01086.txt.bz2 On Fri, Dec 19, 2008 at 06:29:48PM -0500, Jason Merrill wrote: > 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. You're right, that works too. I've so far just checked this testcase, will do full bootstrap/regtest soon. 2008-11-04 Jakub Jelinek Manuel López-Ibáñez PR c++/36921 * c-common.c (warn_about_parentheses): Remove ARG_UNUSED from arg_left. Don't warn about X<=Y<=Z if comparison's type isn't boolean. * g++.dg/warn/pr36921.C: New. --- gcc/c-common.c.jj 2008-11-15 11:13:56.000000000 +0100 +++ gcc/c-common.c 2008-12-20 00:40:03.000000000 +0100 @@ -8059,7 +8059,7 @@ warn_array_subscript_with_type_char (tre void warn_about_parentheses (enum tree_code code, - enum tree_code code_left, tree ARG_UNUSED (arg_left), + enum tree_code code_left, tree arg_left, enum tree_code code_right, tree arg_right) { if (!warn_parentheses) @@ -8169,9 +8169,11 @@ warn_about_parentheses (enum tree_code c default: if (TREE_CODE_CLASS (code) == tcc_comparison && ((TREE_CODE_CLASS (code_left) == tcc_comparison - && code_left != NE_EXPR && code_left != EQ_EXPR) + && code_left != NE_EXPR && code_left != EQ_EXPR + && TREE_CODE (TREE_TYPE (arg_left)) == BOOLEAN_TYPE) || (TREE_CODE_CLASS (code_right) == tcc_comparison - && code_right != NE_EXPR && code_right != EQ_EXPR))) + && code_right != NE_EXPR && code_right != EQ_EXPR + && TREE_CODE (TREE_TYPE (arg_right)) == BOOLEAN_TYPE))) warning (OPT_Wparentheses, "comparisons like % do not " "have their mathematical meaning"); return; --- gcc/testsuite/g++.dg/warn/pr36921.C.jj 2008-12-20 00:37:34.000000000 +0100 +++ gcc/testsuite/g++.dg/warn/pr36921.C 2008-12-20 00:37:34.000000000 +0100 @@ -0,0 +1,27 @@ +/* PR 36921: comparison operator can be overloaded. Do not emit + warnings in such case. + { dg-do compile } + { dg-options "-Wparentheses" } +*/ +struct A {}; +A operator<(A, A) { return A(); } +A operator>(A, A) { return A(); } +A operator<=(A, A) { return A(); } +A operator>=(A, A) { return A(); } +A operator==(A, A) { return A(); } +A operator!=(A, A) { return A(); } + +int main() { + A() < A() < A(); // should not emit warning + 1 < 2 < 3; // { dg-warning "mathematical meaning" "parentheses" } + A() > A() > A(); // should not emit warning + 1 > 2 > 3; // { dg-warning "mathematical meaning" "parentheses" } + A() <= A() <= A(); // should not emit warning + 1 <= 2 <= 3; // { dg-warning "mathematical meaning" "parentheses" } + A() >= A() >= A(); // should not emit warning + 1 >= 2 >= 3; // { dg-warning "mathematical meaning" "parentheses" } + + A() == A() < A (); // { dg-warning "suggest parentheses" "parentheses" } + A() < A() != A (); // { dg-warning "suggest parentheses" "parentheses" } + return 0; +} Jakub