Article View: gnu.g++.bug
Article #222Segmentation fault in g++ 1.39.1
From: Ralph Melton
Date: Mon, 10 Aug 1992 21:28
Date: Mon, 10 Aug 1992 21:28
1991 lines
34489 bytes
34489 bytes
The included file causes g++ 1.39.1 to generate a segmentation fault.
Is this fixed in a later version?
This is occurring on a Sparcstation II running SunOS Release 4.1.1 (GS16).
g++ was installed using the files '/solo/local/gcc-1.39/tm-sparc.h'
and '/solo/local/gcc-1.39/config/sparc.md'.
The file 'tempexpand.C' was generated with 'g++ -E template.C > tempexpand.C'.
This is a script of the compilation:
Script started on Mon Aug 10 14:11:53 1992
theforce% g++ -v tempexpand.C
g++ version 1.39.1 (based on GCC 1.39)
/usr/local/lib/gcc-cpp -+ -v -undef -D__GNUC__ -D__GNUG__ -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ tempexpand.C /usr/tmp/cca06383.cpp
GNU CPP version 1.39
/usr/local/lib/gcc-cc1plus /usr/tmp/cca06383.cpp -quiet -dumpbase tempexpand.C -version -o /usr/tmp/cca06383.s
GNU C++ version 1.39.1 (based on GCC 1.39) (sparc) compiled by GNU C version 1.39.
default target switches: -mfpu -mepilogue
template.C:47: parse error before `<'
template.C:54: parse error before `public'
template.C: In function int mu_int (char *):
template.C:56: warning: implicit declaration of function `set_name'
template.C: In function int mu_int (int):
template.C:61: operator = not defined
template.C: At top level:
template.C:63: wrong number of parameters op `operator ='
template.C:63: `operator =' must have at least one class type
template.C:63: operator has no user-defined argument type
template.C:64: warning: data definition lacks type or storage class
template.C:65: parse error before `}'
template.C:68: parse error before `<'
template.C:73: conflicting types for `assigned'
template.C:52: previous declaration of `assigned'
template.C:73: warning: data definition lacks type or storage class
template.C:74: parse error before `}'
template.C:87: `mu_int' fails to be an aggregate typedef
template.C:87: parse error before `<'
template.C: In function int mu_bool ():
template.C:94: parse error before `;'
template.C: At top level:
template.C:99: parse error before `::'
template.C: In function int mu_bool ():
template.C:99: redefinition of `int mu_bool ()'
template.C:94: here is the previous declaration of `int mu_bool ()'
template.C: In function int mu_bool ():
template.C:99: base initializers not allowed for non-member functions
template.C:99: parse error before `)'
template.C:101: parse error before `::'
template.C:102: wrong number of parameters op `operator ='
template.C:102: `operator =' must have at least one class type
template.C:102: operator has no user-defined argument type
template.C: In function int operator = (int):
template.C:106: `value' undeclared (first use this function)
template.C:106: (Each undeclared identifier is reported only once
template.C:106: for each function it appears in.)
template.C: At top level:
template.C:110: warning: type specifier omitted for parameter
template.C:110: parse error before `&'
template.C:111: wrong number of parameters to `operator <<'
template.C:111: `operator <<' must have at least one class type
template.C:111: operator has no user-defined argument type
template.C: In function class ostream &operator << (...):
template.C:113: `x' undeclared (first use this function)
template.C: At top level:
template.C:118: parse error before `<'
template.C:124: parse error before `public'
template.C:126: warning: data definition lacks type or storage class
template.C:127: warning: data definition lacks type or storage class
template.C:128: parse error before `&'
template.C:128: wrong number of parameters to `operator []'
template.C:128: `operator []' must have at least one class type
template.C:128: operator has no user-defined argument type
template.C:128: warning: data definition lacks type or storage class
template.C:129: parse error before `}'
template.C:132: parse error before `<'
template.C:145: conflicting types for `name'
template.C:123: previous declaration of `name'
template.C:145: warning: `name' was declared `extern' and later `static'
template.C:123: warning: previous declaration of `name'
template.C:145: `n' undeclared, outside of functions
template.C:145: warning: data definition lacks type or storage class
template.C:147: parse error before `for'
template.C:161: parse error before `<'
template.C:163: parse error before `<'
template.C:174: Segmentation violation
g++: Program cc1plus got fatal signal 11.
>> g++: 1
theforce% exit
theforce% exit
script done on Mon Aug 10 14:12:26 1992
script done on Mon Aug 10 14:12:27 1992
This is the offending file:
--- cut here ---
# 1 "template.C"
# 1 "/usr/local/lib/g++-include/std.h" 1
#pragma once
#pragma interface
# 1 "/usr/local/lib/g++-include/stddef.h" 1
#pragma once
#pragma interface
typedef unsigned int size_t;
typedef long int ptrdiff_t;
typedef unsigned short wchar_t;
# 32 "/usr/local/lib/g++-include/std.h" 2
# 1 "/usr/local/lib/g++-include/stdio.h" 1
#pragma once
#pragma interface
# 106 "/usr/local/lib/g++-include/stdio.h"
# 142 "/usr/local/lib/g++-include/stdio.h"
# 192 "/usr/local/lib/g++-include/stdio.h"
# 222 "/usr/local/lib/g++-include/stdio.h"
extern struct _iobuf {
int _cnt;
char* _ptr;
char* _base;
int _bufsiz;
short _flag;
char _file;
} _iob[];
typedef struct _iobuf FILE;
# 271 "/usr/local/lib/g++-include/stdio.h"
# 331 "/usr/local/lib/g++-include/stdio.h"
extern "C" {
int _doprnt(const char*, void*, FILE*);
int _doscan(FILE*, const char*, ...);
int _filbuf(FILE*);
int _flsbuf(unsigned, FILE*);
int fclose(FILE*);
FILE* fdopen(int, const char*);
int fflush(FILE*);
int fgetc(FILE*);
char* fgets(char*, int, FILE *);
FILE* fopen(const char*, const char*);
int fprintf(FILE*, const char* ...);
int fputc(int, FILE*);
int fputs(const char*, FILE*);
int fread(void*, int, int, FILE*);
FILE* freopen(const char*, const char*, FILE*);
int fscanf(FILE*, const char* ...);
int fseek(FILE*, long, int);
long ftell(FILE *);
int fwrite(const void*, int, int, FILE*);
char* gets(char*);
int getw(FILE*);
int pclose(FILE*);
FILE* popen(const char*, const char*);
int printf(const char* ...);
int puts(const char*);
int putw(int, FILE*);
int rewind(FILE*);
int scanf(const char* ...);
int setbuf(FILE*, char*);
int setbuffer(FILE*, char*, int);
int setlinebuf(FILE*);
int setvbuf(FILE*, char*, int, int);
int sscanf(char*, const char* ...);
FILE* tmpfile();
int ungetc(int, FILE*);
int vfprintf(FILE*, const char*, ...);
int vprintf(const char*, ... );
char* sprintf(char*, const char* ...);
char* vsprintf(char*, const char*, ...);
}
# 33 "/usr/local/lib/g++-include/std.h" 2
extern "C" {
void volatile _exit(int);
void volatile abort(void);
int abs(int);
int access(const char*, int);
int acct(const char*);
unsigned alarm(unsigned);
double atof(const char*);
int atoi(const char*);
long atol(const char*);
int bind(int, void*, int);
void bcopy(const void*, void*, int);
int brk(void*);
int bsearch (const void *, const void *, unsigned long,
unsigned long, auto int (*ptf)(const void*, const void*));
void* calloc(unsigned, unsigned);
void cfree(void*);
int chdir(const char*);
int chmod(const char*, int);
int chown(const char*, int, int);
long clock(void);
int close(int);
int creat(const char*, unsigned long int);
char* crypt(const char*, const char*);
char* ctermid(char*);
char* cuserid(char*);
double drand48(void);
int dup(int);
int dup2(int, int);
int dysize(int);
char* ecvt(double, int, int*, int*);
char* encrypt(char*, int);
double erand(short*);
int execl(const char*, const char *, ...);
int execle(const char*, const char *, ...);
int execlp(const char*, const char*, ...);
int exect(const char*, const char**, char**);
int execv(const char*, const char**);
int execve(const char*, const char**, char**);
int execvp(const char*, const char**);
void volatile exit(int);
int fchmod(int, int);
int fchown(int, int, int);
int fcntl(int, int, ...);
char* fcvt(double, int, int*, int*);
int ffs(int);
int flock(int, int);
int fork(void);
void free(void*);
int fsync(int);
long ftok(const char*, int);
int ftruncate(int, unsigned long);
char* gcvt(double, int, char*);
char* getcwd(char*, int);
int getdomainname(char*, int);
int getdtablesize(void);
int getegid(void);
char* getenv(const char*);
int geteuid(void);
int getgid(void);
int getgroups(int, int*);
long gethostid(void);
int gethostname(char*, int);
char* getlogin(void);
int getopt(int, const char**, const char*);
int getpagesize(void);
char* getpass(const char*);
int getpgrp(...);
int getpid(void);
int getppid(void);
int getpriority(int, int);
int getpw(int, char*);
unsigned getuid(void);
char* getwd(char*);
char* initstate(unsigned, char*, int);
int ioctl(int, int, void*);
int isatty(int);
long jrand48(short*);
int kill(int, int);
int killpg(int, int);
void lcong48(short*);
int link(const char*, const char*);
int listen(int, int);
int lock(int, int, long);
long lrand48(void);
long lseek(int, long, int);
void* malloc(unsigned);
unsigned malloc_usable_size(void*);
void* memalign(unsigned, unsigned);
void* memccpy(void*, const void*, int, int);
void* memchr(const void*, int, int);
int memcmp(const void*, const void*, int);
void* memcpy(void*, const void*, int);
void* memset(void*, int, int);
int mkdir(const char*, int);
int mknod(const char*, int, int);
int mkstemp(char*);
char* mktemp(char*);
long mrand48(void);
int nice(int);
long nrand48(short*);
int open(const char*, int, ...);
void volatile pause(void);
void perror(const char*);
int pipe(int*);
int profil(char*, int, int, int);
int psignal(unsigned, char*);
int ptrace(int, int, int, int);
int putenv(const char*);
void qsort(void*, unsigned int, unsigned, auto int (*ptf)(void*,void*));
int rand(void);
long random(void);
int read(int, void*, unsigned);
int readlink(const char*, char*, int);
void* realloc(void*, unsigned);
int rename(const char*, const char*);
int rmdir(const char*);
void* sbrk(int);
short* seed48(short*);
int send(int, char*, int, int);
int setgid(int);
int sethostname(char*, int);
int setkey(const char*);
int setpgrp(...);
int setpriority(int, int, int);
int setregid(int, int);
int setreuid(int, int);
char* setstate(char*);
int setuid(int);
int sigblock(int);
int siginterrupt(int, int);
int sigpause(int);
int sigsetmask(int);
unsigned sleep(unsigned);
int socket(int, int, int);
int srand(unsigned int);
void srand48(long);
void srandom(int);
int stime(long*);
char* strcat(char*, const char*);
char* strchr(const char*, int);
int strcmp(const char*, const char*);
char* strcpy(char*, const char*);
int strcspn(const char*, const char*);
char* strdup(const char*);
int strlen(const char*);
char* strncat(char*, const char*, int);
int strncmp(const char*, const char*, int);
char* strncpy(char*, const char*, int);
char* strpbrk(const char*, const char*);
char* strrchr(const char*, int);
int strspn(const char*, const char*);
double strtod(const char*, char**);
char* strtok(char*, const char*);
long strtol(const char*, char**, int);
void swab(void*, void*, int);
int symlink(const char*, const char*);
int syscall(int, ...);
int system(const char*);
char* tempnam(const char*, const char*);
int tgetent(const char*, const char*);
int tgetnum(const char*);
int tgetflag(const char*);
char* tgetstr(const char *, char **);
char* tgoto(const char*, int, int);
long time(long*);
char* tmpnam(char*);
int tputs(const char *, int, auto int (*)());
int truncate(const char*, unsigned long);
char* ttyname(int);
int ttyslot(void);
unsigned ualarm(unsigned, unsigned);
long ulimit(int, long);
int unlink(const char*);
unsigned usleep(unsigned);
int vadvise(int);
void* valloc(unsigned);
int vfork(void);
int vhangup(void);
int wait(int*);
int write(int, const void*, unsigned);
}
# 252 "/usr/local/lib/g++-include/std.h"
extern "C" {
int bcmp(const void*, const void*, int);
void bzero(void*, int);
char* index(const char*, int);
char* rindex(const char*, int);
}
extern char** environ;
extern volatile int errno;
extern char* sys_errlist[];
extern int sys_nerr;
extern char* optarg;
extern int opterr;
extern int optind;
extern "C" void* alloca(unsigned long);
# 1 "template.C" 2
# 1 "/usr/local/lib/g++-include/stdarg.h" 1
#pragma once
#pragma interface
typedef char *va_list;
# 55 "/usr/local/lib/g++-include/stdarg.h"
void va_end (va_list);
# 2 "template.C" 2
# 1 "/usr/local/lib/g++-include/ostream.h" 1
#pragma once
#pragma interface
# 1 "/usr/local/lib/g++-include/File.h" 1
#pragma once
#pragma interface
# 1 "/usr/local/lib/g++-include/builtin.h" 1
#pragma once
#pragma interface
typedef void (*one_arg_error_handler_t)(const char*);
typedef void (*two_arg_error_handler_t)(const char*, const char*);
# 1 "/usr/local/lib/g++-include/math.h" 1
#pragma once
#pragma interface
# 70 "/usr/local/lib/g++-include/math.h"
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 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
#pragma once
#pragma interface
# 66 "/usr/local/lib/g++-include/values.h"
# 175 "/usr/local/lib/g++-include/values.h"
# 155 "/usr/local/lib/g++-include/math.h" 2
# 45 "/usr/local/lib/g++-include/builtin.h" 2
long gcd(long, long);
long lg(unsigned long);
double pow(double, long);
long pow(long, long);
double start_timer();
double return_elapsed_time(double last_time = 0.0);
char* itoa(long x, int base = 10, int width = 0);
char* itoa(unsigned long x, int base = 10, int width = 0);
char* itoa(long long x, int base = 10, int width = 0);
char* itoa(unsigned long long x, int base = 10, int width = 0);
char* dtoa(double x, char cvt = 'g', int width = 0, int prec = 6);
char* hex(long x, int width = 0);
char* hex(unsigned long x, int width = 0);
char* hex(int x, int width = 0);
char* hex(short x, int width = 0);
char* hex(unsigned int x, int width = 0);
char* hex(unsigned short x, int width = 0);
char* oct(long x, int width = 0);
char* oct(unsigned long x, int width = 0);
char* oct(int x, int width = 0);
char* oct(short x, int width = 0);
char* oct(unsigned int x, int width = 0) ;
char* oct(unsigned short x, int width = 0);
char* dec(long x, int width = 0);
char* dec(unsigned long x, int width = 0);
char* dec(int x, int width = 0);
char* dec(short x, int width = 0);
char* dec(unsigned int x, int width = 0) ;
char* dec(unsigned short x, int width = 0);
char* form(const char* fmt ...);
char* chr(char ch, int width = 0);
char* str(const char* s, int width = 0);
unsigned int hashpjw(const char*);
unsigned int multiplicativehash(int);
unsigned int foldhash(double);
extern void default_one_arg_error_handler(const char*);
extern void default_two_arg_error_handler(const char*, const char*);
extern two_arg_error_handler_t lib_error_handler;
extern two_arg_error_handler_t
set_lib_error_handler(two_arg_error_handler_t f);
double abs(double arg);
float abs(float arg);
short abs(short arg);
long abs(long arg);
int sign(long arg);
int sign(double arg);
long sqr(long arg);
double sqr(double arg);
int even(long arg);
int odd(long arg);
long lcm(long x, long y);
void setbit(long& x, long b);
void clearbit(long& x, long b);
int testbit(long x, long b);
signed char min(signed char a, signed char b);
unsigned char min(unsigned char a, unsigned char b);
signed short min(signed short a, signed short b);
unsigned short min(unsigned short a, unsigned short b);
signed int min(signed int a, signed int b);
unsigned int min(unsigned int a, unsigned int b);
signed long min(signed long a, signed long b);
unsigned long min(unsigned long a, unsigned long b);
float min(float a, float b);
double min(double a, double b);
signed char max(signed char a, signed char b);
unsigned char max(unsigned char a, unsigned char b);
signed short max(signed short a, signed short b);
unsigned short max(unsigned short a, unsigned short b);
signed int max(signed int a, signed int b);
unsigned int max(unsigned int a, unsigned int b);
signed long max(signed long a, signed long b);
unsigned long max(unsigned long a, unsigned long b);
float max(float a, float b);
double max(double a, double b);
# 274 "/usr/local/lib/g++-include/builtin.h"
# 31 "/usr/local/lib/g++-include/File.h" 2
# 1 "/usr/local/lib/g++-include/Fmodes.h" 1
#pragma once
#pragma interface
enum io_mode
{
io_readonly = 0,
io_writeonly = 1,
io_readwrite = 2,
io_appendonly = 3,
io_append = 4,
};
enum access_mode
{
a_createonly = 0,
a_create = 1,
a_useonly = 2,
a_use = 3,
};
enum state_value
{
_good = 0,
_eof = 1,
_fail = 2,
_bad = 4
};
# 35 "/usr/local/lib/g++-include/File.h" 2
class Filebuf;
class File
{
friend class Filebuf;
protected:
FILE* fp;
char* nm;
char rw;
state_value state;
long stat;
void initialize();
void reinitialize(const char*);
char *readline (int chunk_number, char terminator);
public:
File();
File(const char* filename, io_mode m, access_mode a);
File(const char* filename, const char* m);
File(int filedesc, io_mode m);
File(FILE* fileptr);
File(int sz, char* buf, io_mode m);
~File();
File& open(const char* filename, io_mode m, access_mode a);
File& open(const char* filename, const char* m);
File& open(int filedesc, io_mode m);
File& open(FILE* fileptr);
File& close();
File& remove();
int filedesc();
const char* name();
void setname(const char* newname);
int iocount();
int rdstate();
int eof();
int fail();
int bad();
int good();
int readable();
int writable();
int is_open();
operator void*();
void error();
void clear(state_value f = _good);
void set(state_value f);
void unset(state_value f);
File& failif(int cond);
void check_state();
File& get(char& c);
File& put(char c);
File& unget(char c);
File& putback(char c);
File& put(const char* s);
File& get (char* s, int n, char terminator = '\n');
File& getline(char* s, int n, char terminator = '\n');
File& gets (char **s, char terminator = '\n');
File& read(void* x, int sz, int n);
File& write(void* x, int sz, int n);
File& form(const char* ...);
File& scan(const char* ...);
File& flush();
File& flush(char ch);
int fill();
File& seek(long pos, int seek_mode=0);
long tell();
File& setbuf(int buffer_kind);
File& setbuf(int size, char* buf);
File& raw();
};
extern void verbose_File_error_handler(const char*);
extern void quiet_File_error_handler(const char*);
extern void fatal_File_error_handler(const char*);
extern one_arg_error_handler_t File_error_handler;
extern one_arg_error_handler_t set_File_error_handler(one_arg_error_handler_t);
# 320 "/usr/local/lib/g++-include/File.h"
# 39 "/usr/local/lib/g++-include/ostream.h" 2
# 1 "/usr/local/lib/g++-include/streambuf.h" 1
#pragma once
#pragma interface
enum open_mode
{
input=0,
output=1,
append=2
};
class streambuf
{
public:
char* base;
char* pptr;
char* gptr;
char* eptr;
char alloc;
streambuf();
streambuf(char* buf, int buflen);
virtual ~streambuf();
int doallocate();
int allocate();
int must_overflow(int ch);
virtual int overflow(int c = (-1) );
virtual int underflow();
int sgetc();
int snextc();
void stossc();
int sputbackc(char);
int sputc(int c = (-1) );
virtual streambuf* setbuf(char* buf, int buflen, int preloaded_count = 0);
int sputs(const char* s);
int sputsn(const char* s, int len);
virtual const char* name();
virtual streambuf* open(const char* name, open_mode m);
virtual streambuf* open(const char* filename, io_mode m, access_mode a);
virtual streambuf* open(const char* filename, const char* m);
virtual streambuf* open(int filedesc, io_mode m);
virtual streambuf* open(FILE* fileptr);
virtual int is_open();
virtual int close();
virtual void error();
};
# 163 "/usr/local/lib/g++-include/streambuf.h"
# 40 "/usr/local/lib/g++-include/ostream.h" 2
# 1 "/usr/local/lib/g++-include/filebuf.h" 1
#pragma once
#pragma interface
class filebuf: public streambuf
{
public:
int fd;
char opened;
int overflow(int c = (-1) );
int underflow();
filebuf();
filebuf(int newfd);
filebuf(int newfd, char* buf, int buflen);
~filebuf();
streambuf* open(const char* name, open_mode m);
streambuf* open(const char* filename, io_mode m, access_mode a);
streambuf* open(const char* filename, const char* m);
streambuf* open(int filedesc, io_mode m);
streambuf* open(FILE* fileptr);
int is_open();
int close();
};
# 41 "/usr/local/lib/g++-include/ostream.h" 2
# 1 "/usr/local/lib/g++-include/Filebuf.h" 1
#pragma once
#pragma interface
class Filebuf: public streambuf
{
public:
File* Fp;
void init_streambuf_ptrs();
int overflow(int c = (-1) );
int underflow();
Filebuf();
Filebuf(const char* filename, io_mode m, access_mode a);
Filebuf(const char* filename, const char* m);
Filebuf(int filedesc, io_mode m);
Filebuf(FILE* fileptr);
~Filebuf();
const char* name();
streambuf* setbuf(char* buf, int buflen, int preloaded_count = 0);
streambuf* open(const char* name, open_mode m);
streambuf* open(const char* filename, io_mode m, access_mode a);
streambuf* open(const char* filename, const char* m);
streambuf* open(int filedesc, io_mode m);
streambuf* open(FILE* fileptr);
int is_open();
int close();
void error();
};
# 42 "/usr/local/lib/g++-include/ostream.h" 2
class istream;
class ostream
{
friend class istream;
protected:
streambuf* bp;
state_value state;
char ownbuf;
public:
ostream(const char* filename, io_mode m, access_mode a);
ostream(const char* filename, const char* m);
ostream(int filedesc, io_mode m);
ostream(FILE* fileptr);
ostream(int sz, char* buf);
ostream(int filedesc, char* buf, int buflen);
ostream(int filedesc);
ostream(streambuf* s);
~ostream();
ostream& open(const char* filename, io_mode m, access_mode a);
ostream& open(const char* filename, const char* m);
ostream& open(int filedesc, io_mode m);
ostream& open(FILE* fileptr);
ostream& open(const char* filenam, open_mode m);
ostream& close();
ostream& flush();
int rdstate();
int eof();
int fail();
int bad();
int good();
int readable();
int writable();
int is_open();
operator void*();
int operator !();
const char* name();
char* bufptr();
void error();
void clear(state_value f = _good);
void set(state_value f);
void unset(state_value);
ostream& failif(int cond);
ostream& put(char c);
ostream& put(const char* s);
ostream& put(const char* s, int slen);
ostream& form(const char* fmt, ...);
ostream& operator << (short n);
ostream& operator << (unsigned short n);
ostream& operator << (int n);
ostream& operator << (unsigned int n);
ostream& operator << (long n);
ostream& operator << (unsigned long n);
ostream& operator << (long long n);
ostream& operator << (unsigned long long n);
ostream& operator << (float n);
ostream& operator << (double n);
ostream& operator << (const char* s);
ostream& operator << (const void* ptr);
ostream& operator << (char c);
};
extern ostream cout;
extern ostream cerr;
# 254 "/usr/local/lib/g++-include/ostream.h"
# 3 "template.C" 2
enum bool { FALSE, TRUE };
class Error_handler
{
int num_errors;
public:
Error_handler() { num_errors = 0; }
Error( const char *fmt, ... );
};
Error_handler::Error( const char *fmt... )
{
va_list argp;
(__builtin_saveregs (), argp = ((char *) &( fmt) + (((sizeof ( fmt) + sizeof (int) - 1) / sizeof (int)) * sizeof (int)) )) ;
vfprintf( (&_iob[2]) , fmt, argp);
;
fprintf( (&_iob[2]) , "\n");
num_errors++;
}
Error_handler Error_h;
char *tsprintf (char *fmt, ...)
{
static char temp_buffer[1000];
va_list argp;
char *retval;
(__builtin_saveregs (), argp = ((char *) &(fmt) + (((sizeof (fmt) + sizeof (int) - 1) / sizeof (int)) * sizeof (int)) )) ;
vsprintf(temp_buffer, fmt, argp);
;
retval = new char[ strlen(temp_buffer) + 1 ];
strcpy(retval, temp_buffer);
return ( retval );
}
template<int lb, int ub>
class mu_int
{
protected:
int value;
bool assigned;
char *name;
public:
void set_name( char *n) { name = n; };
mu_int(char *n) { assigned = FALSE; set_name(n); };
mu_int(void) { assigned = FALSE; set_name(0 ); };
mu_int(int val)
{
set_name("Parameter or function result");
operator=(val);
};
int operator= (int val);
operator int();
};
template<int lb, int ub> int mu_int<lb, ub>::operator= (int val)
{
if ( ( val <= ub ) && ( val >= lb ) )
{
value = val;
assigned = TRUE;
}
else Error_h.Error("%d not in range for %s.",val, name);
return val;
}
template<int lb, int ub> mu_int<lb, ub>::operator int()
{
if ( !assigned )
Error_h.Error("%s not initialized before reference.",name);
else return ( value );
}
class mu_bool: public mu_int<0,1>
{
public:
mu_bool (char *name);
mu_bool ( void);
bool operator= ( int val );
};
mu_bool::mu_bool(char *n) : mu_simple(n) {}
mu_bool::mu_bool( void ) : mu_simple( void ) {}
bool mu_bool::operator= ( int val)
{
value = val != 0 ? 1 : 0;
assigned = TRUE;
}
ostream& operator<<(ostream& s, mu_bool& x)
{
static char* values[] = {"false","true"};
cout << values[ int(x) ];
}
template<class elt, int lb, int ub>
class mu_array
{
elt array[ub - lb + 1];
char *name;
public:
set_name(char *n);
mu_arr(char *n);
mu_arr(void);
elt& operator[] (int index);
};
template<class elt, int lb, int ub>mu_array<elt,lb,ub>::mu_arr( char *n)
{
set_name(n);
}
template<class elt, int lb, int ub>mu_array<elt,lb,ub>::mu_arr( void )
{
}
template<class elt, int lb, int ub>mu_array<elt,lb,ub>::set_name( char *n)
{
int i;
name = n;
for ( i = lb; i <= ub; i++ )
array[i - lb].set_name( tsprintf("%s[%d]",n,i) );
}
template<class elt, int lb, int ub>elt& mu_array<elt,lb,ub>::operator[] (int index)
{
if ( ( index >= lb) && ( index <= ub ) )
return array[ index - lb ];
else Error_h.Error("%d not in range of %s.",index,name);
}
typedef mu_int<0,1> mu_bit;
typedef mu_array<mu_bit,1,3> mu_arr;
class mu_rec
{
char *name;
public:
set_name(char *n);
mu_bit f1;
mu_arr f2;
mu_rec(char *n) { set_name(n); };
};
mu_rec::set_name(char *n)
{
name = n;
f1.set_name( tsprintf("%s.f1",n) );
f2.set_name( tsprintf("%s.f2",n) );
}
main()
{
mu_int<1,4> foo("foo");
mu_bit bar("bar");
mu_bool tf("tf");
mu_arr A("A");
mu_rec rec("rec");
foo = 3;
cout << foo << '\n';
foo = foo + 5;
cout << bar + 1 << '\n';
bar = 0;
tf = tf && ( 0 == 1 );
cout << tf << '\n';
cout << rec.f2[6] << '\n';
rec.f2[1] = 3;
}
//--- end of file "tempexpand.C"
Technical Details
Message-ID:
<9208102128.AA06555@theforce.Stanford.EDU>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!theforce.stanford.edu!ralphShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!theforce.stanford.edu!ralph From: ralph@theforce.stanford.edu (Ralph Melton) Subject: Segmentation fault in g++ 1.39.1 Message-ID: <9208102128.AA06555@theforce.Stanford.EDU> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Mon, 10 Aug 1992 21:28:33 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 1992