This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
g++ 1.1b : template problem with enum
- To: egcs-bugs at cygnus dot com
- Subject: g++ 1.1b : template problem with enum
- From: "Isabelle Dauthieu p.36 236" <dauthieu at onera dot fr>
- Date: Thu, 15 Oct 1998 15:27:16 +0200 (MET DST)
- Reply-To: "Isabelle Dauthieu p.36 236" <dauthieu at onera dot fr>
The problems evocated in this mail are encountered with egcs1.1b both on Linux
(GNU/Debian on Pentium) and on Solaris2.6 (on Sun4 station)
I encountered some problem with the following code :
----------test.cc--------------------------------
namespace test
{
template <class T>
class Temp
{
public:
typedef enum
{
empty,
full
} State;
private:
class Bug
{
public:
Bug(const T& toto, const State& state);
private:
T m_toto;
State m_state;
};
public:
Temp(const T&);
private:
Bug<T> m_bug;
};
}
template <class T> test::Temp<T>::Bug::Bug(const T& toto, const
test::Temp<T>::State& state)
: m_toto(toto), m_state(state)
{}
template <class T> test::Temp<T>::Temp(const T& toto)
: m_bug(toto, test::Temp<T>::empty)
{}
// instanciations
template class test::Temp<int>;
template class test::Temp<int>::Bug;
int main(int, char **)
{
test::Temp<int> temp(0);
}
--------------------------------------------------
when compiling with the command :
gcc -Wall -fno-implicit-templates test.cc -o test
the results of the compilation are :
test.cc:29: prototype for `::test::Temp<T>::Bug::Bug(const T &, enum
::test::Temp<T>::State &)' does not match any in class `::test::Temp<T>::Bug'
test.cc:16: candidate is: ::test::Temp<T>::Bug::Bug(const T &, const enum
::test::Temp<T>::State &)
test.cc: In method `::test::Temp<T>::Bug::Bug(const T &, enum
::test::Temp<T>::State &)':
test.cc:29: template definition of non-template `::test::Temp<T>::Bug::Bug(const
T &, enum ::test::Temp<T>::State &)'
test.cc: In function `int main(int, char **)':
test.cc:42: warning: unused variable `class ::test::::test::Temp<int> temp'
test.cc: In method `::test::::test::Temp<int>::Temp<int>(const int &)':
test.cc:37: instantiated from here
test.cc:33: warning: initialization of non-const reference `enum
::test::::test::Temp<int>::State &' from rvalue
`::test::::test::Temp<int>::State'
test.cc:16: warning: in passing argument 2 of `Temp<int>::Bug::Bug<int>(const
int &, ::test::::test::Temp<int>::State &)'
It seems the compiler didn't see the const in the definition of the Bug
constructor. (Or perhaps I misunderstood something).
Is it a compiler bug, or did I miswrite something ?
If I comment the const in the declaration of the Bug constructor, the compiler
tells me:
test.cc: In function `int main(int, char **)':
test.cc:42: warning: unused variable `class ::test::::test::Temp<int> temp'
test.cc: In method `::test::::test::Temp<int>::Temp<int>(const int &)':
test.cc:37: instantiated from here
test.cc:33: warning: initialization of non-const reference `enum
::test::::test::Temp<int>::State &' from rvalue
`::test::::test::Temp<int>::State'
test.cc:29: warning: in passing argument 2 of `Temp<int>::Bug::Bug<int>(const
int &, ::test::::test::Temp<int>::State &)'
I don't understand the second warning (l33). Could someone explain me what
happens here ?
And last question : why do I need to explicitely instanciate
test::Temp<int>::Bug, shouldn't it be instanciated with the first instanciation
(test::Temp<int>) ?
Isabelle Dauthieu
dauthieu@onera.fr