Article View: gnu.g++.bug
Article #1301g++ internal compiler error
From: jimc
Date: Fri, 18 Dec 1992 03:45
Date: Fri, 18 Dec 1992 03:45
569 lines
9229 bytes
9229 bytes
Gnu g++ v2.3.2 for Sparc-Sun-SunOS 4.1.1
Upon encountering an obscure combination of screwups, including an
attempted workaround for "nonfunction templates not supported", g++
catches some kind of internal error.
Fixincludes has been run on the header files. The libg++ and g++-include
used here is v2.2. Fixed.h is my own creation, however. Some of the
member function bodies are missing in an attempt to simplify unrelated
debugging. The definition of template<> gorf is also missing, which might
have a lot to do with the bug.
James F. Carter (213) 825-2897
UCLA-Mathnet; 6221 MSA; 405 Hilgard Ave.; Los Angeles, CA, USA 90024-1555
Internet: jimc@math.ucla.edu BITNET: jimc%math.ucla.edu@INTERBIT
UUCP:...!{ucsd,ames,ncar,gatech,purdue,rutgers,decvax,uunet}!math.ucla.edu!jimc
---------- Compiler output
Fixed.h:41: static member `scalef' must be defined separately from its declaration
trees.C: In function `int main (int, char **)':
trees.C:12: parse error before `Fixd12'
trees.C:14: `GORF12' undeclared (first use this function)
trees.C:14: (Each undeclared identifier is reported only once
trees.C:14: for each function it appears in.)
trees.C:15: `test12' undeclared (first use this function)
Fixed.h: At top level:
Fixed.h:41: static member `scalef' must be defined separately from its declaration
trees.C: In function `int main (int, char **)':
trees.C:18: Internal compiler error.
trees.C:18: Please report this to `bug-g++@prep.ai.mit.edu'.
----------- The program (g++ -E trees.C)
# 1 "trees.C"
# 1 "Fixed.h" 1
# 1 "/usr/local/lib/g++-include/math.h" 1 3
#pragma interface
# 64 "/usr/local/lib/g++-include/math.h" 3
extern "C" {
double acos(double);
double acosh(double);
double asin(double);
double asinh(double);
double atan(double);
double atan2(double, double);
double atanh(double);
double cbrt(double);
double ceil(double);
double copysign(double,double);
double cos(double);
double cosh(double);
double drem(double,double);
double erf(double);
double erfc(double);
double exp(double);
double expm1(double);
double fabs(double);
double finite(double);
double floor(double);
double fmod(double, double);
double frexp(double, int*);
double gamma(double);
double hypot(double,double);
double infnan(int);
int isinf(double);
int isnan(double);
double j0(double);
double j1(double);
double jn(int, double);
double ldexp(double, int);
double lgamma(double);
double log(double);
double log10(double);
double log1p(double);
double logb(double);
double modf(double, double*);
double pow(double, double);
double rint(double);
double scalb(double, int);
double sin(double);
double sinh(double);
double sqrt(double);
double tan(double);
double tanh(double);
double y0(double);
double y1(double);
double yn(int, double);
double aint(double);
double anint(double);
int irint(double);
int nint(double);
}
struct libm_exception
{
int type;
char* name;
double arg1, arg2, retval;
};
extern "C" int matherr(libm_exception*);
# 1 "/usr/local/lib/g++-include/values.h" 1 3
# 57 "/usr/local/lib/g++-include/values.h" 3
# 166 "/usr/local/lib/g++-include/values.h" 3
# 150 "/usr/local/lib/g++-include/math.h" 2 3
# 7 "Fixed.h" 2
class Fixed_base {
public:
typedef short BASE;
enum { BITS = 8*sizeof(BASE),
GUARD_BITS = 2 };
protected:
BASE v;
Fixed_base() { }
Fixed_base(BASE i) : v(i) { }
public:
BASE peek() { return v; }
void poke(BASE i) { v = i; }
Fixed_base& operator >>= (int i)
{ v >>= i; return *this; }
protected:
static BASE* sintab;
static const long trigscale;
static Fixed_base sin(BASE w);
static Fixed_base cos(BASE w)
{ w += (1 << (8*sizeof(BASE) - 2)); return sin(w); }
static BASE round(double d)
{ return (BASE)(floor(d + 0.5)); }
};
template <int n> class Fixed : public Fixed_base {
public:
enum { FRAC_BITS = n,
INT_BITS = 8*sizeof(BASE) - (n + 1)};
protected:
static double scalef = 1 << n;
public:
Fixed() { }
Fixed(BASE i) : Fixed_base(i<<n) { }
Fixed(int i) : Fixed_base(i<<n) { }
Fixed(double w) : Fixed_base(round(w*scalef)) { }
Fixed(const Fixed_base& f) : Fixed_base(f) { }
operator double () const { return v/scalef; }
Fixed operator + (Fixed b) const { b.v += v; return b; }
Fixed operator - (Fixed b) const { b.v = v - b.v; return b; }
Fixed operator * (Fixed b) const
{ b.v = ((long)v * b.v) >> n; return b; }
Fixed operator / (Fixed b) const
{ b.v = ((long)v << n) / b.v; return b; }
Fixed operator << (int i) const { Fixed z; z.v = v << i; return z; }
Fixed operator >> (int i) const { Fixed z; z.v = v >> i; return z; }
Fixed& operator += (Fixed b) { v += b.v; return *this; }
Fixed& operator -= (Fixed b) { v -= b.v; return *this; }
Fixed& operator *= (Fixed b)
{ v = ((long)v * b.v) >> n; return *this; }
Fixed& operator /= (Fixed b)
{ v = ((long)v << n) / b.v; return *this; }
Fixed& operator <<= (int i) { v <<= i; return *this; }
Fixed& operator >>= (int i) { v >>= i; return *this; }
Fixed operator ++ () { ++v; return *this; }
Fixed operator ++ (int) { Fixed w(*this); ++v; return w; }
Fixed operator -- () { --v; return *this; }
Fixed operator -- (int) { Fixed w(*this); --v; return w; }
int operator == (Fixed b) const { return v == b.v; }
int operator != (Fixed b) const { return v != b.v; }
int operator <= (Fixed b) const { return v <= b.v; }
int operator < (Fixed b) const { return v < b.v; }
int operator >= (Fixed b) const { return v >= b.v; }
int operator > (Fixed b) const { return v > b.v; }
Fixed operator - () const
{ Fixed w; w.v = -v; return w; }
friend Fixed abs(const Fixed a);
static double epsilon() { return 1.0/(1 << FRAC_BITS); }
Fixed sin()
{ return Fixed_base::sin((trigscale * v) >> INT_BITS) >>= INT_BITS; }
Fixed cos()
{ return Fixed_base::cos((trigscale * v) >> INT_BITS) >>= INT_BITS; }
};
template <int n> inline Fixed<n> abs(const Fixed<n> a)
{ return (a.v >= 0) ? a : -a; }
# 1 "/usr/local/lib/g++-include/math.h" 1 3
# 215 "/usr/local/lib/g++-include/math.h" 3
# 106 "Fixed.h" 2
const long Fixed_base::trigscale =
(long)((1L << BITS)/ 3.14159265358979323846 + 0.5);
Fixed_base::BASE* Fixed_base::sintab = 0;
Fixed_base Fixed_base::sin(BASE v) {
static const FRAC_BITS = BITS - 2;
static const BASE half = 1 << FRAC_BITS;
static const int trig_bits = (BITS - 1)/2 - 1;
static const int ntab = 1 << trig_bits;
static char init = 0;
if (! init) {
init = 1;
sintab = new BASE[2*(ntab+1)];
double w = 0.25* 3.14159265358979323846 /ntab;
double u = w;
double sincoeff = (1L << BITS)*(1.0 - w*w/6.0);
double coscoeff = (1 << GUARD_BITS)* 3.14159265358979323846 ;
for (int i = 0; i <= ntab; ++i, u += 2*w)
sintab[i] = (BASE)(sincoeff*round(::sin(u)));
sintab[i+ntab+1] = (BASE)(coscoeff*round(::cos(u)));
}
BASE frac = v & (half - 1);
if (v & half) frac = half - frac;
static const BASE lin_bits = FRAC_BITS - trig_bits;
static const BASE lin_mask = (1 << lin_bits) - 1;
BASE index = frac >> lin_bits;
BASE offset = frac & lin_mask;
const BASE ofsofs = 1 << (lin_bits - 1);
BASE r = sintab[index] +
((sintab[index + ntab + 1]*(offset - ofsofs)) >> GUARD_BITS);
static const BASE sign_bit = 1 << (FRAC_BITS + 1);
return (v & sign_bit) ? -r : r;
}
# 907 "Fixed.h"
# 7 "trees.C" 2
int main(int , char** ) {
typedef Fixed<12> Fixd12;
typedef gorf<Fixd12> GORF12;
GORF12 test12;
test12.testfixed();
typedef Fixed<9> Fixd9;
typedef gorf<Fixd9> GORF9;
GORF9 test9;
test9.testfixed();
typedef Fixed<4> Fixd4;
typedef gorf<Fixd4> GORF4;
GORF4 test4;
test4.testfixed();
return 0;
}
Technical Details
Message-ID:
<9212181945.AA14236@malibu.pic.ucla.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!pic.ucla.edu!jimcShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!pic.ucla.edu!jimc From: jimc@pic.ucla.edu Subject: g++ internal compiler error Message-ID: <9212181945.AA14236@malibu.pic.ucla.edu> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Fri, 18 Dec 1992 03:45:44 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 570