[Bug c++/105569] [12/13 Regression] -Waddress warns on dynamic_cast

cvs-commit at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu May 26 21:11:45 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105569

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:6f56efa94e845db0d5c934ca202295019bf334c1

commit r13-784-g6f56efa94e845db0d5c934ca202295019bf334c1
Author: Marek Polacek <polacek@redhat.com>
Date:   Wed May 11 14:38:49 2022 -0400

    c++: improve -Waddress warnings with *_cast [PR105569]

    This patch improves the diagnostic for -Waddress when it warns for

      if (dynamic_cast<A*>(&ref))
        // ...

    where 'ref' is a reference, which cannot be null.  In particular, it
    changes
    warning: comparing the result of pointer addition '(((A*)ref) +
((sizetype)(*(long int*)((& ref)->B::_vptr.B + -24))))' and NULL
    to
    warning: the compiler can assume that the address of 'ref' will never be
NULL

            PR c++/105569

    gcc/cp/ChangeLog:

            * typeck.cc (warn_for_null_address): Improve the warning when
            the POINTER_PLUS_EXPR's base is of reference type.

    gcc/testsuite/ChangeLog:

            * g++.dg/warn/Waddress-9.C: New test.


More information about the Gcc-bugs mailing list