egcs-970929: bug in overloading resolution

Dirk Herrmann
Wed Oct 1 10:15:00 GMT 1997


I'm still being bothered by a bug which is in egcs at least since 970907.
With 970929 I was for the first time able to compile and link my code
completely. (I know it was in 970907 as well, because at that time a
warning indicated the problem. The warning is gone since at least 970924,
but the fact is still the same. I reported it on September, 10th on this
list: overloading resolution: funny warnings. The example below shows a
different (for me: worse) aspect of the same problem.)

OK, the details:

template<class Container>
class range_iterator
    explicit range_iterator(Container& c) 
	: pos(c.begin()), end(c.end()) {}
    ~range_iterator() {}

    [... lots of standard iterator member functions deleted]
    operator bool() const 
	{ return pos != end; }
    operator typename Container::iterator() 
        { return pos; }

    typename Container::iterator pos;
    typename Container::iterator end;

The intention is to have an iterator with a bool conversion. It also can
be used at any place where the Container::iterator would be used, due to 
the second implicit conversion function. (NOTE: I'm aware that this is
possibly no good style!)

With g++ the following worked allright (excuse any typos):

for (range_iterator< vector<int> > i(someVector); i; ++i) { ... }

egcs decides to _not_ use the bool conversion operator for the condition
part of the for statement, but instead the conversion to 
vector<int>::iterator, which is int* (or int** ? anyway, a pointer in the
STL implementation coming with egcs!) and thus requires an additional
conversion from pointer to bool. Since this pointer is not NULL at the
end of the vector, the code above is broken.

There are two possibilities:
1) egcs is wrong. From an intuitive point of view I believe so, but I
   have not a very thorough understanding of the CD2 overloading
2) I am wrong. In this case accept my apologies to bother you with it. My
   punishment will be that I have to remove the conversion to 
   Container::iterator and change my code whereever this was used.
   Nevertheless, please let me know via mail.

Best regards and thanks for all the good work in gcc/egcs
Dirk Herrmann
Beat the following spammer sites at their own game! SEND SPAM MAIL TO:

More information about the Gcc-bugs mailing list