This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/27336] New: "this" pointer is not assumed to be not null
- From: "guillaume dot melquiond at ens-lyon dot fr" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 27 Apr 2006 11:29:17 -0000
- Subject: [Bug c++/27336] New: "this" pointer is not assumed to be not null
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
I noticed that GCC tends to litter the assembly code with null checks and jumps
(especially for dynamic casts) even when the pointer cannot be null. This is
especially true for "this": unless I am mistaken, calling a nonstatic member
with "this" not pointing to an object of the correct type (or a derived type)
is undefined behavior. So GCC should assume it is not null. I tried the
following testcase with 3.4.6, 4.0.3, and 4.1.0; GCC was never able to optimize
the return value to "true" when compiling with -O3.
struct A { bool g(); };
bool A::g() { return this; }
--
Summary: "this" pointer is not assumed to be not null
Product: gcc
Version: 4.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: guillaume dot melquiond at ens-lyon dot fr
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27336