public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/23767] New: std::vector iterator implementation wrong
@ 2005-09-07 17:03 afra at cs dot stanford dot edu
  2005-09-07 17:04 ` [Bug c++/23767] " afra at cs dot stanford dot edu
                   ` (26 more replies)
  0 siblings, 27 replies; 28+ messages in thread
From: afra at cs dot stanford dot edu @ 2005-09-07 17:03 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2005-09-12  9:46 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-07 17:03 [Bug c++/23767] New: std::vector iterator implementation wrong afra at cs dot stanford dot edu
2005-09-07 17:04 ` [Bug c++/23767] " afra at cs dot stanford dot edu
2005-09-07 17:06 ` [Bug libstdc++/23767] " afra at cs dot stanford dot edu
2005-09-07 17:13 ` pinskia at gcc dot gnu dot org
2005-09-07 19:22 ` chris at bubblescope dot net
2005-09-07 19:22 ` chris at bubblescope dot net
2005-09-07 19:33 ` pcarlini at suse dot de
2005-09-07 19:37 ` pcarlini at suse dot de
2005-09-07 19:40 ` pcarlini at suse dot de
2005-09-07 20:07 ` chris at bubblescope dot net
2005-09-07 20:14 ` pcarlini at suse dot de
2005-09-07 20:19 ` bangerth at dealii dot org
2005-09-07 20:27 ` pcarlini at suse dot de
2005-09-07 20:40 ` chris at bubblescope dot net
2005-09-07 20:45 ` pcarlini at suse dot de
2005-09-07 20:51 ` chris at bubblescope dot net
2005-09-07 20:55 ` bangerth at dealii dot org
2005-09-07 20:58 ` pcarlini at suse dot de
2005-09-07 21:04 ` pcarlini at suse dot de
2005-09-07 21:07 ` chris at bubblescope dot net
2005-09-07 21:27 ` bangerth at dealii dot org
2005-09-07 21:36 ` pcarlini at suse dot de
2005-09-07 22:40 ` bangerth at dealii dot org
2005-09-08  3:36 ` fang at csl dot cornell dot edu
2005-09-11 14:32 ` pcarlini at suse dot de
2005-09-12  9:44 ` cvs-commit at gcc dot gnu dot org
2005-09-12  9:46 ` pcarlini at suse dot de
2005-09-12  9:46 ` pcarlini at suse dot de

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).