public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/14154] New: g++ silently creates incorrect code when "this" used in initializer list
@ 2004-02-16  7:28 rls at tamu dot edu
  2004-02-16  7:33 ` [Bug c++/14154] " rls at tamu dot edu
  2004-02-16 12:08 ` pinskia at gcc dot gnu dot org
  0 siblings, 2 replies; 3+ messages in thread
From: rls at tamu dot edu @ 2004-02-16  7:28 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/14154] g++ silently creates incorrect code when "this" used in initializer list
  2004-02-16  7:28 [Bug c++/14154] New: g++ silently creates incorrect code when "this" used in initializer list rls at tamu dot edu
@ 2004-02-16  7:33 ` rls at tamu dot edu
  2004-02-16 12:08 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: rls at tamu dot edu @ 2004-02-16  7:33 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From rls at tamu dot edu  2004-02-16 07:33 -------
Created an attachment (id=5755)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=5755&action=view)
Testcase that reproduces the problem

Here is the source file that I used to cause the error.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14154


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/14154] g++ silently creates incorrect code when "this" used in initializer list
  2004-02-16  7:28 [Bug c++/14154] New: g++ silently creates incorrect code when "this" used in initializer list rls at tamu dot edu
  2004-02-16  7:33 ` [Bug c++/14154] " rls at tamu dot edu
@ 2004-02-16 12:08 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-02-16 12:08 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-02-16 12:07 -------
Confirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |diagnostic
      Known to fail|                            |2.95.3 3.1 3.3.3 3.3 3.4.0
                   |                            |3.5.0
   Last reconfirmed|0000-00-00 00:00:00         |2004-02-16 12:07:56
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14154


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-02-16 12:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-16  7:28 [Bug c++/14154] New: g++ silently creates incorrect code when "this" used in initializer list rls at tamu dot edu
2004-02-16  7:33 ` [Bug c++/14154] " rls at tamu dot edu
2004-02-16 12:08 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).