You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@stdcxx.apache.org by "Farid Zaripov (JIRA)" <ji...@apache.org> on 2008/08/22 13:14:44 UTC
[jira] Issue Comment Edited: (STDCXX-976) std::uninitialized_copy()
requires InputIterator::operator*() returning lvalue
[ https://issues.apache.org/jira/browse/STDCXX-976?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12624652#action_12624652 ]
farid edited comment on STDCXX-976 at 8/22/08 4:13 AM:
---------------------------------------------------------------
The [latest change|http://svn.apache.org/viewvc?rev=687762&view=rev] is not enough - see the updated testcase http://svn.apache.org/viewvc?rev=688053&view=rev
We shouldn't use const reference if the _InputIterator::operator*() returns non-const reference.
The possible solutions are:
1. Add const _TypeU& overloads of the __rw_construct()
2. Use placement new right in std::uninitialized_copy() instead of using __rw_construct()
was (Author: farid):
The [http://svn.apache.org/viewvc?rev=687762&view=rev|latest change] is not enough - see the updated testcase http://svn.apache.org/viewvc?rev=688053&view=rev
We shouldn't use const reference if the _InputIterator::operator*() returns non-const reference.
The possible solutions are:
1. Add const _TypeU& overloads of the __rw_construct()
2. Use placement new right in std::uninitialized_copy() instead of using __rw_construct()
> std::uninitialized_copy() requires InputIterator::operator*() returning lvalue
> ------------------------------------------------------------------------------
>
> Key: STDCXX-976
> URL: https://issues.apache.org/jira/browse/STDCXX-976
> Project: C++ Standard Library
> Issue Type: Bug
> Components: 25. Algorithms
> Affects Versions: 4.2.0, 4.2.1
> Environment: All
> Reporter: Farid Zaripov
> Assignee: Farid Zaripov
> Fix For: 4.2.2
>
> Original Estimate: 1h
> Remaining Estimate: 1h
>
> The following test fails to compile:
> {code}
> #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;
> }
> {code}
> {noformat}
> 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
> ]
> {noformat}
> The fix:
> {noformat}
> 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);
> {noformat}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.