[LLVMbugs] [Bug 10455] New: Silent conversion of vector<T*>::iterator to vector<T*>::const_iterator&

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sat Jul 23 06:02:01 PDT 2011


           Summary: Silent conversion of  vector<T*>::iterator to
           Product: libc++
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
        AssignedTo: hhinnant at apple.com
        ReportedBy: oroppas at gmail.com
                CC: llvmbugs at cs.uiuc.edu


The following piece of code cannot be compiled by either clang++/g++ with

#include <vector>
#include <unordered_map>

typedef std::vector<int*> KernelVector;
typedef std::unordered_map<int*,KernelVector> KernelVectorMap;

int main()
  KernelVectorMap::const_iterator kernel;
  KernelVector::const_iterator subkernel = kernel->second.begin();

  std::distance( kernel->second.begin(), subkernel );

  return 0;

clang++ -std=c++0x -stdlib=libc++ ./const_iterator.cpp 
./const_iterator.cpp:12:3: error: no matching function for call to 'distance'
  std::distance( kernel->second.begin(), subkernel );
/usr/include/c++/v1/iterator:478:1: note: candidate template ignored: deduced
conflicting types for parameter
      '_InputIter' ('std::__1::__wrap_iter<int **>' vs.
'std::__1::__wrap_iter<int *const *>')
distance(_InputIter __first, _InputIter __last)
1 error generated.


g++ -std=c++0x -I /usr/include/c++/v1/ ./const_iterator.cpp 
./const_iterator.cpp: In function ‘int main()’:
./const_iterator.cpp:12:52: error: no matching function for call to
./const_iterator.cpp:12:52: note: candidate is:
/usr/include/c++/v1/iterator:479:47: note: template<class _InputIter> typename
std::__1::iterator_traits::difference_type std::__1::distance(_InputIter,

Can iterator be silently converted to const_iterator in the case like

Please take a look at the comment by David Blaikie:

Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list