This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/69970] New: Surprising warning with -Wnonnull-compare - 'this' compared to NULL
- From: "larsbj at gullik dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 26 Feb 2016 02:11:10 +0000
- Subject: [Bug c++/69970] New: Surprising warning with -Wnonnull-compare - 'this' compared to NULL
- Auto-submitted: auto-generated
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)