https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109568
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Plus, because dynamic_cast<Derived*>((Base*)nullptr) is valid and has to return (Derived*)nullptr, the emitted code effective has to use if (var) var_ref = ... else var_ref = nullptr; if (var_ref->empty ()) and so again, for the case where var is nullptr and is tested in the IL it is clearly invoking empty method on nullptr.