https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99074
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Martin Sebor from comment #2)
> --- a/libstdc++-v3/libsupc++/dyncast.cc
> +++ b/libstdc++-v3/libsupc++/dyncast.cc
> @@ -47,6 +47,8 @@ __dynamic_cast (const void *src_ptr, // object started
> from
> const __class_type_info *dst_type, // desired target type
> ptrdiff_t src2dst) // how src and dst are related
> {
> + if (!src_ptr)
> + return NULL;
Shouldn't this use __builtin_expect(!src_ptr, 0)? The FE is only supposed to
call this function when we have a non-null pointer, which is true for programs
with no UB, so this check potentially pessimizes correct programs.