GCC 2.95 internal error wrt template base type specification without template
Andy Glew
glewATcs.wisc.edu
Thu Sep 16 14:46:00 GMT 1999
BRIEF
=====
Attempts to access basetype fields such as
[1] this->class1::field1
which should be fully specified as
[2] this->class1<int>::field1
i.e. which should have a template parameter
specified, cause an internal compiler error.
Note: [1] may be illegal code, although my reading
of the ANSI C++ standard suggests that it is not.
However, earlier versions of the compiler,
such as EGCS 1.1.2, accepted [1] but did not accept [2].
In any case, an internal compiler error is not desirable, right?
This bug has been seen under EGCS 2.95 and 2.95.1
Config
------
egeus ~/hack/gcc2.95-internal-error 24 : uname -a
SunOS egeus 5.6 Generic_105182-15 i86pc i386
egeus ~/hack/gcc2.95-internal-error 25 :
DETAIL
======
Below is a test program. Still further below is a shell session
demonstrating the error message. Finally, a script demonstrating
no bug if a minor change is made.
Test Program - demonstrates bug
-------------------------------
#include <iostream>
template<class T>
class class1 {
public:
T field1;
class1() { field1 = 1; }
};
class class2 : public class1<int> {
public:
int field1;
int field2;
class2() { field1 = 2; field2 = 22; this->class1::field1 = -2; }
void print() const {
cout << field1 << " " << field2 << " " << this->class1::field1 << "\n";
}
};
main()
{
class2 c2;
c2.print();
}
Shell Session demonstrating bug
-------------------------------
egeus ~/hack/gcc2.95-internal-error 9 : gcc -v
Reading specs from /s/gcc-2.95/sunx86_56/lib/gcc-lib/i386-pc-solaris2.6/2.95/specs
gcc version 2.95 19990728 (release)
egeus ~/hack/gcc2.95-internal-error 10 : make test
g++ test.cc -o test
test.cc: In method `class2::class2()':
test.cc:12: Internal compiler error.
test.cc:12: Please submit a full bug report.
test.cc:12: See <URL: http://egcs.cygnus.com/faq.html#bugreport > for instructions.
make: *** [test] Error 1
egeus ~/hack/gcc2.95-internal-error 13 : /s/gcc-2.95.1/sunx86_57/bin/gcc test.cc -o test
test.cc: In method `class2::class2()':
test.cc:12: Internal compiler error.
test.cc:12: Please submit a full bug report.
test.cc:12: See <URL: http://www.gnu.org/software/gcc/faq.html#bugreport > for instructions.
egeus ~/hack/gcc2.95-internal-error 14 :
Shell Session Demonstrating non-bug with newly supported syntax
---------------------------------------------------------------
egeus ~/hack/gcc2.95-internal-error 18 : cat test-good.cc
#include <iostream>
template<class T>
class class1 {
public:
T field1;
class1() { field1 = 1; }
};
class class2 : public class1<int> {
public:
int field1;
int field2;
class2() { field1 = 2; field2 = 22; this->class1<int>::field1 = -2; }
void print() const {
cout << field1 << " " << field2 << " " << this->class1<int>::field1 << "\n";
}
};
main()
{
class2 c2;
c2.print();
}
egeus ~/hack/gcc2.95-internal-error 19 : diff -u2 test.cc test-good.cc
--- test.cc Thu Sep 16 16:40:37 1999
+++ test-good.cc Thu Sep 16 16:40:05 1999
@@ -12,7 +12,7 @@
int field1;
int field2;
- class2() { field1 = 2; field2 = 22; this->class1::field1 = -2; }
+ class2() { field1 = 2; field2 = 22; this->class1<int>::field1 = -2; }
void print() const {
- cout << field1 << " " << field2 << " " << this->class1::field1 << "\n";
+ cout << field1 << " " << field2 << " " << this->class1<int>::field1 << "\n";
}
};
egeus ~/hack/gcc2.95-internal-error 20 : make test-good
make: `test-good' is up to date.
egeus ~/hack/gcc2.95-internal-error 21 : rm test-good
egeus ~/hack/gcc2.95-internal-error 22 : make test-good
g++ test-good.cc -o test-good
egeus ~/hack/gcc2.95-internal-error 23 : ./test-good
2 22 -2
egeus ~/hack/gcc2.95-internal-error 24 :
---
Andy Glew, glew@cs.wisc.edu
[Place URGENT in email subject line for mail filter prioritization.]
More information about the Gcc-bugs
mailing list