From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7430 invoked by alias); 14 Aug 2011 12:25:30 -0000 Received: (qmail 7416 invoked by uid 22791); 14 Aug 2011 12:25:29 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 14 Aug 2011 12:25:16 +0000 From: "mikpe at it dot uu.se" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/50012] [4.5/4.6/4.7 Regression] C++ front end misses -Wsign-compare warnings when extraneous parentheses are present Date: Sun, 14 Aug 2011 12:43:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: mikpe at it dot uu.se X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.5.4 X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-08/txt/msg01292.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50012 --- Comment #2 from Mikael Pettersson 2011-08-14 12:25:12 UTC --- The warning is lost due to this fragment of r148952 (with the rest of r148952 disabled): --- gcc/cp/typeck.c (revision 148951) +++ gcc/cp/typeck.c (revision 148952) @@ -4018,6 +4018,8 @@ cp_build_binary_op (location_t location, if ((short_compare || code == MIN_EXPR || code == MAX_EXPR) && warn_sign_compare + && !TREE_NO_WARNING (orig_op0) + && !TREE_NO_WARNING (orig_op1) /* Do not warn until the template is instantiated; we cannot bound the ranges of the arguments until that point. */ && !processing_template_decl In this test case (the foo() function) the LHS is a parenthesized expression, and cp/semantics.c:finish_parenthesized_expr() contains the following gem: tree finish_parenthesized_expr (tree expr) { if (EXPR_P (expr)) /* This inhibits warnings in c_common_truthvalue_conversion. */ TREE_NO_WARNING (expr) = 1; Disabling either the setting of TREE_NO_WARNING in finish_parenthesized_expr or the && !TREE_NO_WARNING check in cp_build_binary_op restores the warning for this test case. Alas I'm sure something else will break in that case ...