From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3ADCB3857C45; Tue, 21 Jul 2020 20:39:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3ADCB3857C45 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1595363960; bh=mjRWQ2LXkOftGJGDwYmVFX2sc419LP2risWdMhEqTxI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=xbd2uhlmf9Z/N8G/VS8cqXePB8LOY/+XThB2KhuAF7JA+Z79El1syiRFlZFf8Ehog UTztIcIPZcBZ6C30uJROjQNBJ0E1UQ0Um0M8cvpDKcbWQYPW66JFYCARVhbOL7v6Td Zo+EItkMK1KoOoyj8+11SaFayR0CpRmWpKWXvYNE= From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/96003] [11 Regression] spurious -Wnonnull calling a member on the result of static_cast Date: Tue, 21 Jul 2020 20:39:20 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: diagnostic, patch X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: msebor at gcc dot gnu.org X-Bugzilla-Target-Milestone: 11.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jul 2020 20:39:20 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96003 --- Comment #12 from Martin Sebor --- Thanks for the test case. In it, the no-warning bit set on the conditional expression to avoid the warning is cleared before the expression reaches the warning code. The culprit seems to be the cp_fold_convert() function calle= d on the expression: it rebuilds the COND_EXPR but fails to propagate the no-war= ning bit. The change below fixes it but I wouldn't be surprised if this wasn't = the only instance where the no-warning bit might get stripped from an expressio= n. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 300d959278b..67153e3f484 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -8754,6 +8754,7 @@ fold_unary_loc (location_t loc, enum tree_code code, = tree type, tree op0) arg02 =3D fold_build1_loc (loc, code, type, fold_convert_loc (loc, TREE_TYPE (op0), arg02)); + bool nowarn =3D TREE_NO_WARNING (op0); tem =3D fold_build3_loc (loc, COND_EXPR, type, TREE_OPERAND (arg0= , 0), arg01, arg02); @@ -8788,6 +8789,8 @@ fold_unary_loc (location_t loc, enum tree_code code, = tree type, tree op0) TREE_OPERAND (TREE_OPERAND (tem, 1), = 0), TREE_OPERAND (TREE_OPERAND (tem, 2), 0))); + if (nowarn) + TREE_NO_WARNING (tem) =3D true; return tem; } }=