From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 3B8B83857C66 for ; Wed, 2 Dec 2020 05:15:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3B8B83857C66 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-19-a0aamr4lPZCP20XXN0DQ9w-1; Wed, 02 Dec 2020 00:15:45 -0500 X-MC-Unique: a0aamr4lPZCP20XXN0DQ9w-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7D3B11005E49; Wed, 2 Dec 2020 05:15:44 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-145.phx2.redhat.com [10.3.112.145]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0655760854; Wed, 2 Dec 2020 05:15:43 +0000 (UTC) Subject: Re: [10/23] Tweak the way that is_a is implemented To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com References: From: Jeff Law Message-ID: Date: Tue, 1 Dec 2020 22:15:43 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US X-Spam-Status: No, score=-6.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, 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: Wed, 02 Dec 2020 05:15:49 -0000 On 11/13/20 1:16 AM, Richard Sandiford via Gcc-patches wrote: > At the moment, class hierarchies that use is_a are expected > to define specialisations like: > > template <> > template <> > inline bool > is_a_helper ::test (symtab_node *p) > { > return p->type == SYMTAB_FUNCTION; > } > > But this doesn't scale well to larger hierarchies, because it only > defines ::test for an argument that is exactly “symtab_node *” > (and not for example “const symtab_node *” or something that > comes between cgraph_node and symtab_node in the hierarchy). > > For example: > > struct A { int x; }; > struct B : A {}; > struct C : B {}; > > template <> > template <> > inline bool > is_a_helper ::test (A *a) > { > return a->x == 1; > } > > bool f(B *b) { return is_a (b); } > > gives: > > warning: inline function ‘static bool is_a_helper::test(U*) [with U = B; T = C*]’ used but never defined > > and: > > bool f(const A *a) { return is_a (a); } > > gives: > > warning: inline function ‘static bool is_a_helper::test(U*) [with U = const A; T = const C*]’ used but never defined > > This patch instead allows is_a to be implemented by specialising > is_a_helper as a whole, for example: > > template<> > struct is_a_helper : static_is_a_helper > { > static inline bool test (const A *a) { return a->x == 1; } > }; > > It also adds a general specialisation of is_a_helper for const > pointers. Together, this makes both of the above examples work. > > gcc/ > * is-a.h (reinterpret_is_a_helper): New class. > (static_is_a_helper): Likewise. > (is_a_helper): Inherit from reinterpret_is_a_helper. > (is_a_helper): New specialization. OK Jeff