From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by sourceware.org (Postfix) with ESMTP id 8075A384640E for ; Thu, 13 Aug 2020 15:51:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8075A384640E Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-389-sjRw5b2cOduo4q6TMtqMQw-1; Thu, 13 Aug 2020 11:51:49 -0400 X-MC-Unique: sjRw5b2cOduo4q6TMtqMQw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 92645801AB1; Thu, 13 Aug 2020 15:51:48 +0000 (UTC) Received: from ovpn-114-89.phx2.redhat.com (ovpn-114-89.phx2.redhat.com [10.3.114.89]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3CF265C1A3; Thu, 13 Aug 2020 15:51:48 +0000 (UTC) Message-ID: <3050e18bef5c44b0e475515b019a7db31ddbd734.camel@redhat.com> Subject: Re: [PATCH] avoid -Wnonnull on synthesized condition in static_cast (PR 96003) From: Jeff Law Reply-To: law@redhat.com To: Martin Sebor , gcc-patches , Jason Merrill Date: Thu, 13 Aug 2020 09:51:47 -0600 In-Reply-To: References: Organization: Red Hat User-Agent: Evolution 3.36.5 (3.36.5-1.fc32) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Aug 2020 15:51:53 -0000 On Fri, 2020-07-17 at 13:00 -0600, Martin Sebor via Gcc-patches wrote: > The recent enhancement to treat the implicit this pointer argument > as nonnull in member functions triggers spurious -Wnonnull for > the synthesized conditional expression the C++ front end replaces > the pointer with in some static_cast expressions. The front end > already sets the no-warning bit for the test but not for the whole > conditional expression, so the attached fix extends the same solution > to it. > > The consequence of this fix is that user-written code like this: > > static_cast(p ? p : 0)->f (); > or > static_cast(p ? p : nullptr)->f (); > > don't trigger the warning because they are both transformed into > the same expression as: > > static_cast(p)->f (); > > What still does trigger it is this: > > static_cast(p ? p : (T*)0)->f (); > > because here it's the inner COND_EXPR's no-warning bit that's set > (the outer one is clear), whereas in the former expressions it's > the other way around. It would be nice if this worked consistently > but I didn't see an easy way to do that and more than a quick fix > seems outside the scope for this bug. > > Another case reported by someone else in the same bug involves > a dynamic_cast. A simplified test case goes something like this: > > if (dynamic_cast(p)) > dynamic_cast(p)->f (); > > The root cause is the same: the front end emitting the COND_EXPR > > ((p != 0) ? ((T*)__dynamic_cast(p, (& _ZTI1B), (& _ZTI1C), 0)) : 0) > > I decided not to suppress the warning in this case because doing > so would also suppress it in unconditional calls with the result > of the cast: > > dynamic_cast(p)->f (); > > and that doesn't seem helpful. Instead, I'd suggest to make > the second cast in the if statement to reference to T&: > > if (dynamic_cast(p)) > dynamic_cast(*p).f (); Hmmm, I wonder if this would fix a handful of errors I got when doing the testing of the Ranger work for Aldy. Let me throw the new version into the tester and respin just the failing packages. Jeff >