Syntax bug
Pavel A. Kalugin
kalugin@pc358.lps.u-psud.fr
Tue Jan 13 07:55:00 GMT 1998
Here's the code snippet revealing the bug in the C++ parser:
////////////////////////////////////////////////////////////
class X {
public:
X() : data(new char[10]){}
~X() {
delete[] data;
}
operator const char* () const {return data;}
operator char* () {return data;}
private:
char* data;
};
void
foo()
{
X x;
x[0]='q';
}
///////////////////////////////////////////////////////////////
I got the following when compiling it with egsc:
x.cpp: In function `void foo()':
x.cpp:17: ambiguous conversion for array subscript
On the other hand, an _incorrect_ declaration
const operator char* () const {return data;}
makes the compiler quite happy. This bug existed in gcc-2.7.2.3 as well.
The specs of the compiler are:
Reading specs from /usr/local/egcs/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.90.23/specs
gcc version egcs-2.90.23 980102 (egcs-1.0.1 release)
Thanks,
-Pavel
More information about the Gcc-bugs
mailing list