I was compiling the following code and GCC seems to accept the following code.
#include <map>
template<typename K, typename V>
class my_map {
private:
std::map<K, V> mmap;
public:
typedef std::map<K, V>::iterator iterator;
typedef std::map<K, V>::const_iterator const_iterator;
iterator begin() {return mmap.begin();}
const_iterator begin() const {return mmap.begin();}
};
int main()
{
my_map<int, int>::iterator whatever;
return 0;
}
But clang complains about the missing typename
keyword.
The complaint of clang makes more sense to me. Is this a GCC bug?
Edit: Obviously, Where and why do I have to put the "template" and "typename" keywords? does not answer my question, as I am not asking what typename
keyword is, but asking about different behaviors of compilers.
Edit: Now the program is accepted by both clang(from version 16) and gcc.