scp@SFI.SANTAFE.EDU ("Stephen C. Pope") (10/05/89)
I believe (though I'm not exactly sure) that I'm doing
something illegal with the const T& member flagged below.
In any case, g++`s output is behavior is not very helpful
(SparcStation, SunOS4.0.3c, this is the now-obsolete
g++.ytar.Z w/ patches. Could someone try it on the new 1.36.0-???)
gcc -v -O -fstrength-reduce -c t.cc
gcc version 1.36.0- (based on GCC 1.35.98+)
/usr/local/lib/gcc-cpp -+ -v -undef -D__GNUC__ -D__GNUG__ -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__OPTIMIZE__ t.cc /tmp/cca03730.cpp
GNU CPP version 1.35.98
/usr/local/lib/gcc-cc1plus /tmp/cca03730.cpp -quiet -dumpbase t.cc -fstrength-reduce -O -version -o /tmp/cca03730.s
GNU C++ version 1.36.0- (based on GCC 1.35.98+) (sparc) compiled by GNU C version 1.35.98.
default target switches: -mfpu -mepilogue
t.cc: In method int TP::get_r ():
t.cc:19: Segmentation violation
gcc: Program cc1plus got fatal signal 11.
heres the code:
class T {
const int r;
public:
T(int);
int const get_r();
};
class TP {
const T& t; // legal???
public:
TP(int);
int get_r();
void do_something(int);
};
T::T(int i) : r(i) {}
inline int T::get_r() { return r; }
TP::TP(int i) : t(*(new T(i))) {}
inline int TP::get_r() { return t.get_r(); }
void TP::do_something(int i)
{
int a, b, c;
a = 0;
b = 1;
c = i * b + a;
}
main()
{
TP t(16);
int s = 0;
for( int i = 0; i < t.get_r(); ++i ) {
s += i;
t.do_something(s);
}
return s;
}
Stephen Pope
scp@sfi.santafe.edu