This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: PR 58148 patch
- From: François Dumont <frs dot dumont at gmail dot com>
- To: Daniel Krügler <daniel dot kruegler at gmail dot com>
- Cc: Paolo Carlini <paolo dot carlini at oracle dot com>, "libstdc++ at gcc dot gnu dot org" <libstdc++ at gcc dot gnu dot org>
- Date: Wed, 28 Aug 2013 21:30:32 +0200
- Subject: Re: PR 58148 patch
- Authentication-results: sourceware.org; auth=none
- References: <521BB025 dot 3040700 at gmail dot com> <521BBD4F dot 1040300 at oracle dot com> <521D0D5A dot 3060201 at gmail dot com> <521D1001 dot 3080504 at oracle dot com> <CAGNvRgBaXi1LYWC8Gq2p20MO9vrTigZhw7HNBZu-X5pit93vBg at mail dot gmail dot com>
Sorry, I do not understand your remark Daniel.
So here is another proposal using sequence const_pointer as advised by
Paolo. As we are now using it I consider that std::addressof was not
necessary anymore on sequence elements and that sequence it was not
necessary to check that sequence elements address can be passed through
const_pointer. So the code is simpler.
Tested successfully under Linux x86_64.
Ok to commit ?
François
On 08/27/2013 10:48 PM, Daniel Krügler wrote:
2013/8/27 Paolo Carlini <paolo.carlini@oracle.com>:
On 08/27/2013 10:34 PM, François Dumont wrote:
As you seem to be more concern by the usage of experimental
std::common_type than by the usage of const volatile void*I would like to
propose the attached patch.
I don't think we should do that either. For example, if we are using
std::less & co to accommodate for segmented memory etc, I don't think we
should reduce all sorts of pointers to void* pointers, otherwise we could as
well use < & co. No, for 4.9.0 let's do something simple and safe.
Wouldn't it solve the problem, if decltype(*it) is implicitly
convertible to the value type? [I'm sorry, if I missed the essential
context here]
- Daniel
Index: include/debug/functions.h
===================================================================
--- include/debug/functions.h (revision 201966)
+++ include/debug/functions.h (working copy)
@@ -36,7 +36,7 @@
#include <bits/move.h> // for __addressof and addressof
#if __cplusplus >= 201103L
# include <bits/stl_function.h> // for less and greater_equal
-# include <type_traits> // for common_type
+# include <type_traits> // for is_lvalue_reference and __and_
#endif
#include <debug/formatter.h>
@@ -172,27 +172,33 @@
}
#if __cplusplus >= 201103L
+ // Default implementation.
template<typename _Iterator, typename _Sequence,
- typename _InputIterator,
- typename _PointerType1,
- typename _PointerType2>
+ typename _InputIterator>
inline bool
__foreign_iterator_aux4(const _Safe_iterator<_Iterator, _Sequence>& __it,
_InputIterator __other,
- _PointerType1, _PointerType2)
+ typename _Sequence::const_pointer)
{
- typedef typename std::common_type<_PointerType1,
- _PointerType2>::type _PointerType;
+ typedef typename _Sequence::const_pointer _PointerType;
constexpr std::less<_PointerType> __l{};
constexpr std::greater_equal<_PointerType> __ge{};
return (__l(std::addressof(*__other),
- std::addressof(*(__it._M_get_sequence()->_M_base().begin())))
+ &(*(__it._M_get_sequence()->_M_base().begin())))
|| __ge(std::addressof(*__other),
- std::addressof(*(__it._M_get_sequence()->_M_base().end()
- - 1)) + 1));
+ &(*(__it._M_get_sequence()->_M_base().end() - 1)) + 1));
}
-
+
+ // Fallback when address type cannot be implicitely casted to sequence
+ // const_pointer.
+ template<typename _Iterator, typename _Sequence,
+ typename _InputIterator>
+ inline bool
+ __foreign_iterator_aux4(const _Safe_iterator<_Iterator, _Sequence>&,
+ _InputIterator, ...)
+ { return true; }
+
template<typename _Iterator, typename _Sequence, typename _InputIterator>
inline bool
__foreign_iterator_aux3(const _Safe_iterator<_Iterator, _Sequence>& __it,
@@ -208,10 +214,7 @@
if (std::addressof(*(__it._M_get_sequence()->_M_base().end() - 1))
- std::addressof(*(__it._M_get_sequence()->_M_base().begin()))
== __it._M_get_sequence()->size() - 1)
- return (__foreign_iterator_aux4
- (__it, __other,
- std::addressof(*(__it._M_get_sequence()->_M_base().begin())),
- std::addressof(*__other)));
+ return __foreign_iterator_aux4(__it, __other, std::addressof(*__other));
return true;
}
@@ -223,7 +226,7 @@
std::false_type)
{ return true; }
#endif
-
+
/** Checks that iterators do not belong to the same sequence. */
template<typename _Iterator, typename _Sequence, typename _OtherIterator>
inline bool
Index: testsuite/23_containers/vector/modifiers/insert/58148.cc
===================================================================
--- testsuite/23_containers/vector/modifiers/insert/58148.cc (revision 0)
+++ testsuite/23_containers/vector/modifiers/insert/58148.cc (revision 0)
@@ -0,0 +1,35 @@
+// Copyright (C) 2013 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++11" }
+// { dg-do compile }
+
+#include <vector>
+
+void
+test01()
+{
+ std::vector<wchar_t> v;
+ char c = 'a';
+ v.insert(v.begin(), &c, &c);
+}
+
+int main()
+{
+ test01();
+ return 0;
+}