Is the following code supposed to be valid C++ or is GCC right in
rejecting it:
template<typename T> class A;
template<typename T> struct hidden_unless_int { };
template<> struct hidden_inless_int<int> {typedef A<int>& type; };
template<typename T> struct visible_unless_int { typedef A<int>&
type; };
template<> struct visible_unless_int<int> {};
template<typename T>
class A {
public:
typename hidden_unless_int<T>::type operator = (T value) {}
typename visible_unless_int<T>::type operator = (T value) {}
};
A<int> ai;
A<float> af;
There're a couple of things going on here. Clearly overloading on the
returned type alone is not enough to disambiguate (but the specific
case of operator= doesn't allow for the usual trick of an additional
dummy parameter with a default value) . What we would have hoped here
is that the SFINAE rule would have kicked in to filter the set of
possible overloads. Is GCC right in failing on the instantiations
{hidden,visible}_unless_int that do not contain the typedef for type?
[another data point is that comeau C++ - edg based - agrees with GCC,
which strongly suggests that the code above is wrong ]
If the above is illegal code, is there any way to control the
overloading set for operator= ?
Thanks a lot.
Maurizio Vitale