mirror of
https://github.com/gcc-mirror/gcc.git
synced 2026-05-06 23:25:24 +02:00
3c9b99ef7115fa88ef4d744cc2afc424bd5c3ef2
This change allows std::function::target<F>() 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<F*>(ptr). The standard only allows const_cast<T*> when T is an object type. The solution is to use *const_cast<F**>(&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<void, void>): 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 directory contains the GNU Compiler Collection (GCC). The GNU Compiler Collection is free software. See the files whose names start with COPYING for copying permission. The manuals, and some of the runtime libraries, are under different terms; see the individual source files for details. The directory INSTALL contains copies of the installation information as HTML and plain text. The source of this information is gcc/doc/install.texi. The installation information includes details of what is included in the GCC sources and what files GCC installs. See the file gcc/doc/gcc.texi (together with other files that it includes) for usage and porting information. An online readable version of the manual is in the files gcc/doc/gcc.info*. See http://gcc.gnu.org/bugs/ for how to report bugs usefully. Copyright years on GCC source files may be listed using range notation, e.g., 1987-2012, indicating that every year in the range, inclusive, is a copyrightable year that could otherwise be listed individually.
Description
Languages
C++
30.8%
C
30.2%
Ada
14.4%
D
6.1%
Go
5.7%
Other
12.3%