This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/69902] New: Bogus -Wnonnull-compare for: dynamic_cast<T*>(&ref) == nullptr


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

            Bug ID: 69902
           Summary: Bogus -Wnonnull-compare for: dynamic_cast<T*>(&ref) ==
                    nullptr
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sbergman at redhat dot com
  Target Milestone: ---

With GCC built from trunk@233597:

> $ cat test.cc
> struct A { virtual ~A(); };
> struct B: A {};
> bool f(A & a) { return dynamic_cast<B *>(&a) == nullptr; }

> $ gcc/trunk/inst/bin/g++ -Werror -Wnonnull-compare test.cc
> test.cc: In function âbool f(A&)â:
> test.cc:3:46: error: nonnull argument âaâ compared to NULL [-Werror=nonnull-compare]
>  bool f(A & a) { return dynamic_cast<B *>(&a) == nullptr; }
>                         ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
> cc1plus: all warnings being treated as errors

(The warning goes away when changing "== nullptr" to "!= nullptr", or when
adding -fsyntax-only.)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]