The following code does not compile.  According to the compiler, 
't' is overloaded ambiguously.

#include <vector>

struct T {
  typedef std::vector<int> Vector;
  typedef Vector::iterator iterator;
  typedef Vector::const_iterator const_iterator;

  int t( iterator f)             { return *f; }
  int t( const_iterator f) const { return *f; }
};

int main(int, char*[])
{
  std::vector<int> v;
  T t;
  T::const_iterator i = v.begin();

  t.t(i);

  return 0;

}

We've seen this on gcc 3.2.2., 3.4.3, 4.0.1.  Basically, the
const_iterator matches both the iterator and the const_iterator at function
resolution time.  This seems to stem from the implementation of iterator in
std::vector using __normal_iterator.  There is a template copy constructor that
appears to allow this illegal conversion.

Error on:  gcc version 4.0.1 20050727 (Red Hat 4.0.1-5)
----------
test.cc: In function int main(int, char**):
test.cc:18: error: ISO C++ says that these are ambiguous, even though
the
worst conversion for the first is better than the worst conversion for
the
second:
test.cc:10: note: candidate 1: int
T::t(__gnu_cxx::__normal_iterator<const
int*, std::vector<int, std::allocator<int> > >) const
test.cc:9: note: candidate 2: int
T::t(__gnu_cxx::__normal_iterator<int*,
std::vector<int, std::allocator<int> > >)

-- 
           Summary: std::vector iterator implementation wrong
           Product: gcc
           Version: 4.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: afra at cs dot stanford dot edu
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23767

Reply via email to