This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
inherited enums
- To: gcc at gcc dot gnu dot org
- Subject: inherited enums
- From: Kurt Garloff <kurt at garloff dot de>
- Date: Wed, 27 Jun 2001 21:42:21 +0200
- Organization: TUE/NL, SuSE/FRG
Hi,
A bug in the gcc compiler...
This time, both gcc-2.95.3 and gcc-3.0.0 (3.0.1 20010626) are
affected.
If I declare a enum in a base class, I can't use it in the descendant
classes without using a typedef.
(It might be that the language standard actually requires me to use a
typdef, I can't tell for sure, so the code may be illegal.)
Anyway, gcc misbehaves by producing an ICE (2.95.3) or giving a strange
error message (3.0.0) followed by a segfault.
garloff@gum07:~/Linux/C $ gcc -v 2>&1 | tail -1
gcc version 3.0.1 20010626 (prerelease)
garloff@gum07:~/Linux/C $ gcc -o inherited_enum inherited_enum.cpp
inherited_enum.cpp:31: warning: enum typename test2<T>::MyEnum' declares a
new type at namespace scope;
to refer to the inherited type, say enum test2::MyEnum'
(names from dependent base classes are not visible to unqualified name
lookup)
inherited_enum.cpp:31: Internal error: Segmentation fault
[...]
garloff@gum07:~/Linux/C $ gcc -v 2>&1 | tail -1
gcc version 2.95.3 20010315 (SuSE)
garloff@gum07:~/Linux/C $ gcc -o inherited_enum inherited_enum.cpp
inherited_enum.cpp:31: Internal compiler error.
[...]
Test code attached.
Regards,
--
Kurt Garloff <kurt@garloff.de> [Eindhoven, NL]
Physics: Plasma simulations <K.Garloff@Phys.TUE.NL> [TU Eindhoven, NL]
Linux: SCSI, Security <garloff@suse.de> [SuSE Nuernberg, FRG]
(See mail header or public key servers for PGP2 and GPG public keys.)
/** \file inherited_enum.cpp
* Both gcc-2.95.3 and gcc-3.0.0 produce an ICE on this code.
* Note: Using a typedef does solve the problem.
* Using the keyword typename does not help.
* The syntax test1<T>::MyEnum produces the same ICE.
* However, gcc-3.0.0 suggested using test2::MyEnum.
* Doing so, gcc-3.0.0 still complains that test2::MyEnum should be used.
* Afterwards: Internal Error: Segmentation Fault
* I believe the code is legal, but I can't tell for sure.
* (w) Kurt Garloff <kurt@garloff.de>, 2001-06-27, (c) GNU GPL
*/
template <typename T>
class test1
{
public:
test1 (int i) { if (i==0) m_en = EN0; else m_en = EN1; };
protected:
enum MyEnum { EN0, EN1, EN2, EN3 };
MyEnum m_en;
};
template <typename T>
class test2 : public test1<T>
{
public:
test2 (int i, int j) : test1<T>(i) {if (j==0) m_en2 = EN0; else m_en2 = EN1; };
protected:
//enum test1<T>::MyEnum m_en2;
enum test2::MyEnum m_en2;
};
int main ()
{
test1<int> t1(1);
test2<int> t2(1,0);
}
PGP signature