static string member bug on hp
Lars Albertsson
lalle@sics.se
Tue May 5 09:16:00 GMT 1998
The following program causes core dump using egcs-1.0.2 on
hppa1.1-hp-hpux9.05:
#include <iostream>
#include <string>
class foo {
public:
foo() {};
string bar() const { return bar_; };
private:
static string bar_;
};
string foo::bar_("foobar");
int
main(int, char **)
{
foo f;
cout << f.bar() << endl;
return 0;
}
When debugging, gdb seems slightly confused, but either claims
foo::bar_ is optimised out or improperly initialised.
The program is compiled with -gstabs.
/Lalle
(gdb) break main
Breakpoint 1 at 0x3624: file test1.cc, line 19.
(gdb) run
Starting program: /a/muneca/root/ip6/src/test/compiler/test1
Breakpoint 1, main () at test1.cc:19
19 foo f;
(gdb) s
foo::foo (this=0x7b0337b8) at test1.cc:6
6 foo() {};
(gdb) s
6 foo() {};
(gdb) s
main () at test1.cc:21
21 cout << f.bar() << endl;
(gdb) print f
$1 = {bar_ = <optimized out or zero length>}
(gdb) s
foo::bar (this=0x7b0337b8) at test1.cc:8
8 string bar() const { return bar_; };
(gdb) s
basic_string<char, string_char_traits<char>, __default_alloc_template<false, 0> >::basic_string (this=0x7b0337c0, str=0x400010d0)
at /ip6/gnu/egcs-1.0.2/include/g++/std/bastring.h:138
138 basic_string (const basic_string& str): dat (str.rep ()->grab ()) { }
(gdb) s
basic_string<char, string_char_traits<char>, __default_alloc_template<false, 0> >::rep (this=0x400010d0) at /ip6/gnu/egcs-1.0.2/include/g++/std/bastring.h:113
113 Rep *rep () const { return reinterpret_cast<Rep *>(dat) - 1; }
(gdb) print *this
$2 = {npos = <optimized out or zero length>,
nilRep = <optimized out or zero length>, dat = 0x0}
(gdb) s
113 Rep *rep () const { return reinterpret_cast<Rep *>(dat) - 1; }
(gdb) s
grab__Q2t12basic_string3ZcZt18string_char_traits1ZcZt24__default_alloc_template2b0i03Rep (this=0xfffffff0) at /ip6/gnu/egcs-1.0.2/include/g++/std/bastring.h:75
75 charT* grab () { if (selfish) return clone (); ++ref; return data (); }
(gdb) s
Program received signal SIGSEGV, Segmentation fault.
grab__Q2t12basic_string3ZcZt18string_char_traits1ZcZt24__default_alloc_template2b0i03Rep (this=0xfffffff0) at /ip6/gnu/egcs-1.0.2/include/g++/std/bastring.h:75
75 charT* grab () { if (selfish) return clone (); ++ref; return data (); }
More information about the Gcc-bugs
mailing list