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.)