This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/14154] New: g++ silently creates incorrect code when "this" used in initializer list
- From: "rls at tamu dot edu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 16 Feb 2004 07:28:30 -0000
- Subject: [Bug c++/14154] New: g++ silently creates incorrect code when "this" used in initializer list
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
I'm not completely sure that this is the problem...but given the same code MS
Visual C++ warns about "'this' used in argument initialization list". G++
merrily compiles the code and then gets a segfault inside of the C++ standard
library.
Here is a code snippet that will reproduce the problem:
(the command-line to compile: g++ test.cpp -g3 -o test)
------------------------
// The obligatory includes
#include <string>
using namespace std;
class bar; // Forward declaration
class foo {
public:
foo(bar * b); // foo takes a pointer-to-bar
};
class bar {
public:
foo f; // bar has a foo member...
string str;
bar() : f(this) { } //...to which it gives pointer-to-self...
void setString(const string &s) { str = s; }
};
//...which foo uses to call back into the partially-constructed bar
// This is probably not valid, in which case should cause a compile
error/warning
foo::foo(bar * b) { b->setString(string("Die, G++!")); }
int main() {
bar b; // BOOM!
return 0;
}
------------------------
Program received signal SIGSEGV, Segmentation fault.
0xffffffff in ?? ()
Current language: auto; currently c
(gdb) bt
#0 0xffffffff in ?? ()
#1 0x4012f785 in ?? () from /lib/tls/libc.so.6
#2 0x40016b28 in ?? () from /lib/ld-linux.so.2
(gdb)
--
Summary: g++ silently creates incorrect code when "this" used in
initializer list
Product: gcc
Version: 3.3.2
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: rls at tamu dot edu
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i586-mandrake-linux-gnu
GCC host triplet: i586-mandrake-linux-gnu
GCC target triplet: i586-mandrake-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14154