https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69970
Bug ID: 69970 Summary: Surprising warning with -Wnonnull-compare - 'this' compared to NULL Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: larsbj at gullik dot net Target Milestone: --- Compiling this snippet: class Foo { public: explicit Foo(bool) {} }; class Bar { public: Bar() : foo_(new Foo(this)) {} private: Foo * foo_; }; int main() { Bar bar; return 0; } With: g++ -c -Wnonnull-compare nonnull.cpp Gives: nonnull.cpp: In constructor ‘Bar::Bar()’: nonnull.cpp:10:21: warning: nonnull argument ‘this’ compared to NULL [-Wnonnull-compare] : foo_(new Foo(this)) Removing explict makes no difference. g++ -v Using built-in specs. COLLECT_GCC=/opt/gcc/gcc-6/bin/g++ COLLECT_LTO_WRAPPER=/opt/gcc/gcc-6/libexec/gcc/x86_64-pc-linux-gnu/6.0.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../gcc/configure --prefix=/opt/gcc/gcc-6 --enable-checking=release --enable-languages=c,c++,lto Thread model: posix gcc version 6.0.0 20160225 (experimental) (GCC)