From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10415 invoked by alias); 7 Sep 2005 17:03:19 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 9685 invoked by uid 48); 7 Sep 2005 17:03:08 -0000 Date: Wed, 07 Sep 2005 17:03:00 -0000 From: "afra at cs dot stanford dot edu" To: gcc-bugs@gcc.gnu.org Message-ID: <20050907170304.23767.afra@cs.stanford.edu> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug c++/23767] New: std::vector iterator implementation wrong X-Bugzilla-Reason: CC X-SW-Source: 2005-09/txt/msg00832.txt.bz2 List-Id: The following code does not compile. According to the compiler, 't' is overloaded ambiguously. #include struct T { typedef std::vector 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 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 test.cc:9: note: candidate 2: int T::t(__gnu_cxx::__normal_iterator > >) -- 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