This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gcc-3.4 requires 'typename' to use map in a template?


The following code is rejected by gcc-3.4-20031001, but accepted
by gcc-2.95 and gcc-3.2.3:

#include <map>

template <typename T>
class myclass {
        typedef std::map<T, unsigned int> mymap;
public:
        void mymethod() {
            mymap::iterator myvar;
            myvar = 0;
        }
};

Command to reproduce:
$ /usr/local/gcc-3.4-20031001/bin/g++ foo2.cc
foo2.cc: In member function `void myclass<T>::mymethod()':
foo2.cc:8: error: expected `;'
foo2.cc:9: error: `myvar' undeclared (first use this function)

Using the typename keyword seems to be a workaround, as
gcc-3.4-20031001 accepts the following code without complaint:

#include <map>

template <typename T>
class myclass {
        typedef std::map<T, unsigned int> mymap;
public:
        void mymethod() {
            typename mymap::iterator myvar;
            myvar = 0;
        }
};

So is gcc-3.4-20031001 right to require typename here, or is this a bug?
- Dan


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]