Heya, folks. I'm porting some code from a project largely developed in MSVS to use g++. I've found a lot of little differences, mostly things that MSVS allows but g++ does not. Usually it's something involving c++ standards, things that MSVS lets slide, but I'm having trouble seeing just what's wrong with one particular section.
g++ is having trouble matching a call to operator !=, but only in a specific context. Looking up operator != for a particular nested class works if the hosting class is not a template. If I turn the hosting class into a class template, however, everything breaks. I'm either missing something fundamental to c++, or g++ is doing something wrong.
I've learned not to cry "Compiler Bug!" too often, so I wanted to see if anyone here can see what I'm missing.
This worked example shows the working, non-template version, and then the broken, template version. g++ --version gives: g++ (Ubuntu 4.4.1-4ubuntu9) 4.4.1
Working reference version without templates
namespace Works {
struct host {
struct iterator {};
iterator op();
};
bool operator != (host::iterator const& a0, host::iterator const& a1);
bool f() {
return host().op() != host().op();
}
} // namespace Works
Broken version with templates
namespace Broken {
template <typename T>
struct host {
struct iterator {};
iterator op();
};
template <typename T>
bool operator != (typename host<T>::iterator const& a0,
typename host<T>::iterator const& a1);
bool f() {
return host<int>().op() != host<int>().op();
}
} // namespace Broken
The template version fails with the errors:
Main.cpp: In function ‘bool Broken::f()’:
Main.cpp:50: error: no match for ‘operator!=’ in ‘Broken::host<int>().Broken::host<T>::op [with T = int]() != Broken::host<int>().Broken::host<T>::op [with T = int]()’