[PATCH] Make any_cast compare typeinfo as well as function pointers

Christophe Lyon christophe.lyon@linaro.org
Fri May 24 08:57:00 GMT 2019


Hi Jonathan,

On Thu, 23 May 2019 at 16:13, Jonathan Wakely <jwakely@redhat.com> wrote:
>
> It's possible for the function pointer comparison to fail even though
> the type is correct, because the function could be defined multiple
> times with different addresses when shared libraries are in use.
>
> Retain the function pointer check for the common case where the check
> succeeds, but compare typeinfo (if RTTI is enabled) if the first check
> fails.
>
>         * include/experimental/any (__any_caster): Use RTTI if comparing
>         addresses fails, to support non-unique addresses in shared libraries.
>         * include/std/any (__any_caster): Likewise.
>
> Tested powerpc64le-linux, committed to trunk, backports to follow.
>
>

It seems OK on trunk, but on gcc-7/gcc-8 branches I see:
/libstdc++-v3/testsuite/experimental/any/misc/any_cast_neg.cc:20:
/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-aarch64-none-linux-gnu/gcc3/aarch64-none-linux-gnu/libstdc++-v3/include/experimental/any:
In instantiation of '_ValueType
std::experimental::fundamentals_v1::any_cast(const
std::experimental::fundamentals_v1::any&) [with _ValueType = int&]':
/libstdc++-v3/testsuite/experimental/any/misc/any_cast_neg.cc:28:
required from here
/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-aarch64-none-linux-gnu/gcc3/aarch64-none-linux-gnu/libstdc++-v3/include/experimental/any:358:
error: binding reference of type 'int&' to 'const int' discards
qualifiers
compiler exited with status 1
FAIL: experimental/any/misc/any_cast_neg.cc  (test for errors, line 357)
FAIL: experimental/any/misc/any_cast_neg.cc (test for excess errors)

on arm/aarch64

Christophe



More information about the Libstdc++ mailing list