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 [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id F3EC73851C3E for ; Mon, 9 Nov 2020 14:30:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org F3EC73851C3E 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-276-ydY7SoVwPpeSx-DF2Wut4Q-1; Mon, 09 Nov 2020 09:30:11 -0500 X-MC-Unique: ydY7SoVwPpeSx-DF2Wut4Q-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 37DC1E06A7; Mon, 9 Nov 2020 14:30:10 +0000 (UTC) Received: from localhost (unknown [10.33.36.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id C942A5C1D0; Mon, 9 Nov 2020 14:30:09 +0000 (UTC) Date: Mon, 9 Nov 2020 14:30:09 +0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: [committed] libstdc++: Make std::function work better with -fno-rtti Message-ID: <20201109143009.GP503596@redhat.com> References: <20201029144912.GA2368106@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201029144912.GA2368106@redhat.com> X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="ubuMVesmirrCclZT" Content-Disposition: inline X-Spam-Status: No, score=-14.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, 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: Mon, 09 Nov 2020 14:30:16 -0000 --ubuMVesmirrCclZT Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline On 29/10/20 14:49 +0000, Jonathan Wakely wrote: >This change allows std::function::target() to work even without RTTI, >using the same approach as std::any. Because we know what the manager >function would be for a given type, we can check if the stored pointer >has the expected address. If it does, we don't need to use RTTI. If it >isn't equal, we still need to do the RTTI check (when RTTI is enabled) >to handle the case where the same function has different addresses in >different shared objects. > >This also changes the implementation of the manager function to return a >null pointer result when asked for the type_info of the target object. >This not only avoids a warning with -Wswitch -Wsystem-headers, but also >avoids prevents std::function::target_type() from dereferencing an >uninitialized pointer when the linker keeps an instantiation of the >manager function that was compiled without RTTI. > >Finally, this fixes a bug in the non-const overload of function::target >where calling it with a function type F was ill-formed, due to >attempting to use const_cast(ptr). The standard only allows >const_cast when T is an object type. The solution is to use >*const_cast(&ptr) instead, because F* is an object type even if F >isn't. I've also used _GLIBCXX17_CONSTEXPR in function::target so that >it doesn't bother instantiating anything for types that can never be a >valid target. > >libstdc++-v3/ChangeLog: > > * include/bits/std_function.h (_Function_handler): > Define explicit specialization used for invalid target types. > (_Base_manager::_M_manager) [!__cpp_rtti]: Return null. > (function::target_type()): Check for null pointer. > (function::target()): Define unconditionall. Fix bug with > const_cast of function pointer type. > (function::target() const): Define unconditionally, but > only use RTTI if enabled. > * testsuite/20_util/function/target_no_rtti.cc: New test. This fixes a problem with that previous patch. Tested x86_64-linux. Committed to trunk. --ubuMVesmirrCclZT Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" commit 99bf3a817b9d31905dd12448e853ad2685635250 Author: Jonathan Wakely Date: Mon Nov 9 10:09:51 2020 libstdc++: Include even for -fno-rtti [PR 97758] The std::function code now uses std::type_info* even when RTTI is disabled, so it should include unconditionally. Without this, Clang can't compile with -fno-rtti (it works with GCC because std::type_info gets declared automatically by the compiler). libstdc++-v3/ChangeLog: PR libstdc++/97758 * include/bits/std_function.h [!__cpp_rtti]: Include . diff --git a/libstdc++-v3/include/bits/std_function.h b/libstdc++-v3/include/bits/std_function.h index 054d9cbbf02b..1788b882a8aa 100644 --- a/libstdc++-v3/include/bits/std_function.h +++ b/libstdc++-v3/include/bits/std_function.h @@ -36,9 +36,7 @@ # include #else -#if __cpp_rtti -# include -#endif +#include #include #include #include --ubuMVesmirrCclZT--