This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/53515] New: InputIterator version std::advance needs positive check


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: unassigned@gcc.gnu.org
        ReportedBy: faithandbrave@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;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]