Uploaded image for project: 'C++ Standard Library'
  1. C++ Standard Library
  2. STDCXX-976

std::uninitialized_copy() requires InputIterator::operator*() returning lvalue

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.2.0, 4.2.1
    • 4.2.2
    • 25. Algorithms
    • None
    • All

    • Patch Available
    • Regression
    • Compiler Error

    Description

      The following test fails to compile:

      #include <memory>
      #include <iterator>
      
      struct InputIterator: std::iterator<std::input_iterator_tag, char>
      {
          const char *p_;
      
          InputIterator (const char *p): p_ (p) { }
          InputIterator (const InputIterator &rhs): p_ (rhs.p_) { }
      
          InputIterator& operator= (const InputIterator &rhs)
          { p_ = rhs.p_; return *this; }
      
          char operator* () const { return *p_; }
          
          InputIterator& operator++ () { return ++p_, *this; }
          InputIterator operator++ (int) {
              return ++p_, InputIterator (p_ - 1);
          }
      
          bool operator== (const InputIterator &rhs) const { return p_ == rhs.p_; }
          bool operator!= (const InputIterator &rhs) const { return p_ != rhs.p_; }
      };
      
      int main ()
      {
          char src [5] = "abcd";
          char dst [5];
      
          std::uninitialized_copy (InputIterator (src), InputIterator (src + 5), dst);
      
          return 0;
      }
      
      D:\_Libs\stdcxx-4.2.2\include\rw\_specialized.h(168) : error C2665: '__rw::__rw_construct' : none of the 2 overloads can convert parameter 2 from type 'char'
              D:\_Libs\stdcxx-4.2.2\include\rw\_specialized.h(88): could be 'void __rw::__rw_construct<char,char>(_TypeT *,_TypeU &)'
              with
              [
                  _TypeT=char,
                  _TypeU=char
              ]
              D:\_Libs\stdcxx-4.2.2\include\rw\_specialized.h(96): or       'void __rw::__rw_construct<char,char>(volatile _TypeT *,_TypeU &)'
              with
              [
                  _TypeT=char,
                  _TypeU=char
              ]
              while trying to match the argument list '(char *, char)'
              test.cpp(29) : see reference to function template instantiation '_ForwardIterator std::uninitialized_copy<InputIterator,char*>(_InputIterator,_InputIterator,_ForwardIterator)' being compiled
              with
              [
                  _ForwardIterator=char *,
                  _InputIterator=InputIterator
              ]
      

      The fix:

      Index: include/rw/_specialized.h
      ===================================================================
      --- include/rw/_specialized.h	(revision 671890)
      +++ include/rw/_specialized.h	(working copy)
      @@ -85,7 +85,7 @@
       
       template <class _TypeT, class _TypeU>
       inline void
      -__rw_construct (_TypeT* __p, _TypeU& __val)
      +__rw_construct (_TypeT* __p, const _TypeU& __val)
       {
           ::new (_RWSTD_STATIC_CAST (void*, __p)) _TypeT (__val);
       }
      @@ -93,7 +93,7 @@
       
       template <class _TypeT, class _TypeU>
       inline void
      -__rw_construct (volatile _TypeT* __p, _TypeU& __val)
      +__rw_construct (volatile _TypeT* __p, const _TypeU& __val)
       {
           // remove volatile before invoking operator new
           __rw_construct (_RWSTD_CONST_CAST (_TypeT*, __p), __val);
      @@ -103,7 +103,7 @@
       
       template <class _TypeT, class _TypeU>
       inline void
      -__rw_construct_impl (_TypeT* __p, _TypeU& __val)
      +__rw_construct_impl (_TypeT* __p, const _TypeU& __val)
       {
           ::new (_RWSTD_STATIC_CAST (void*, __p)) _TypeT (__val);
       }
      @@ -111,7 +111,7 @@
       
       template <class _TypeT, class _TypeU>
       inline void
      -__rw_construct (volatile _TypeT* __p, _TypeU& __val)
      +__rw_construct (volatile _TypeT* __p, const _TypeU& __val)
       {
           // remove volatile before invoking operator new
           __rw_construct_impl (_RWSTD_CONST_CAST (_TypeT*, __p), __val);
      

      Attachments

        Issue Links

          Activity

            People

              farid Farid Zaripov
              farid Farid Zaripov
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - 1h
                  1h
                  Remaining:
                  Remaining Estimate - 1h
                  1h
                  Logged:
                  Time Spent - Not Specified
                  Not Specified