Article View: gnu.g++.bug
Article #1545g++ ignores static const's in private class section
From: "Douglas C. Schmidt"
Date: Sun, 27 Nov 1988 03:00
Date: Sun, 27 Nov 1988 03:00
80 lines
2550 bytes
2550 bytes
Hi,
I believe the following is valid C++ code. cfront 1.2.1 accepts and
executes it correctly. G++ 1.27 produces the following error message:
----------------------------------------
g++ version 1.27.0
echo use .cc filename extension!
use .cc filename extension!
/usr/public/lib/g++/gcc-cpp+ -v -I/cd/ua/schmidt/include/ -undef
-D__GNU__ -D__GNUG__ -Dsparc -Dsun -Dunix -+ reverse_video.c
/tmp/cca01184.cpp
GNU CPP version 1.27.0
/usr/public/lib/g++/gcc-c++ /tmp/cca01184.cpp -quiet -dumpbase
reverse_video.c -finline-functions -fmemoize-lookups -fsave-memoized
-fchar-charconst -version -o /tmp/cca01184.s
At top level:
reverse_video.c:19: undeclared variable `MAX_SIZE' (first use here)
GNU C++ version 1.27.0 (sparc) compiled by GNU C version 1.28.
----------------------------------------
However, I believe this usage of static constants is allowed.
Here's the code:
----------------------------------------
#include <stream.h>
int tgetent( char *bp, char *name );
char *tgetstr( char *id, char **area );
int tputs( char *cp, int affcnt, int (*outc)( int ) );
char *getlogin ( void );
int putchr( int i ) {
return ( putchar(i) );
}
class Inverse {
private:
// g++ seems to ignore this static constant declaration
static const int MAX_SIZE = 1024;
char sbuf [ MAX_SIZE ];
char *sp;
char bp [ MAX_SIZE ];
char *so_start;
char *so_end;
public:
Inverse ( void ): sp ( sbuf ) {
if ( tgetent ( bp, getenv ( "TERM" ) ) != 1 ) {
cerr << "error: termcap read failure\n",exit ( 1 );
}
so_start = tgetstr ( "so", &sp );
so_end = tgetstr ( "se", &sp );
}
Inverse& operator () ( char *Buf ) {
tputs ( so_start, 1, putchr );
cout << Buf;
tputs ( so_end, 1, putchr );
return ( *this );
}
friend ostream& operator << ( ostream& s, Inverse &i ) { // dummy function
;
}
};
main ( int argc,char *argv[ ] ) {
Inverse V;
cout << "hello, you are " << V ( getlogin ( ) ) << "\n";
}
Technical Details
Message-ID:
<8811261900.aa22841@PARIS.ICS.UCI.EDU>Path:
arc1-ca.pugleaf.net!utzoo!telly!ddsw1!mcdchg!rutgers!tut.cis.ohio-state.edu!ORION.CF.UCI.EDU!schmidt%crimee.ics.uci.eduShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!telly!ddsw1!mcdchg!rutgers!tut.cis.ohio-state.edu!ORION.CF.UCI.EDU!schmidt%crimee.ics.uci.edu
From: schmidt%crimee.ics.uci.edu@ORION.CF.UCI.EDU ("Douglas C. Schmidt")
Newsgroups: gnu.g++.bug
Subject: g++ ignores static const's in private class section
Message-ID: <8811261900.aa22841@PARIS.ICS.UCI.EDU>
Date: 27 Nov 88 03:00:33 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 80