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

             Bug #: 53515
           Summary: InputIterator version std::advance needs positive
                    check
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: faithandbr...@gmail.com


C++11 specification 24.4.4

template <class InputIterator, class Distance>
void advance(InputIterator& i, Distance n);

Requires: n shall be negative only for bidirectional and random access
iterators.

==
libstdc++ std::advance is nothing positive check.
I think InputIterator version std::advance needs positive check.


before code:

template<typename _InputIterator, typename _Distance>
inline void
__advance(_InputIterator& __i, _Distance __n, input_iterator_tag)
{
  // concept requirements
  __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
  while (__n--)
    ++__i;
}


after code (add assert):

template<typename _InputIterator, typename _Distance>
inline void
__advance(_InputIterator& __i, _Distance __n, input_iterator_tag)
{
  // concept requirements
  __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
  _GLIBCXX_DEBUG_ASSERT(__n >= 0);
  while (__n--)
    ++__i;
}

Reply via email to