From dc84fdc8469593faa45895d7e5bcb1f166d6af9c Mon Sep 17 00:00:00 2001 From: fdumont Date: Fri, 30 Aug 2013 20:55:37 +0000 Subject: [PATCH] =?utf8?q?2013-08-30=20=20Fran=C3=A7ois=20Dumont=20=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit PR libstdc++/58148 * include/debug/functions.h (__foreign_iterator_aux4): Use sequence const_pointer as common type to compare pointers. Add a fallback overload in case pointers cannot be cast to sequence const_pointer. * testsuite/23_containers/vector/modifiers/insert/58148.cc: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@202121 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 9 +++++ libstdc++-v3/include/debug/functions.h | 39 ++++++++++++---------- .../23_containers/vector/modifiers/insert/58148.cc | 35 +++++++++++++++++++ 3 files changed, 65 insertions(+), 18 deletions(-) create mode 100644 libstdc++-v3/testsuite/23_containers/vector/modifiers/insert/58148.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c288313f10a..898f0319a20 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,14 @@ 2013-08-30 François Dumont + PR libstdc++/58148 + * include/debug/functions.h (__foreign_iterator_aux4): Use + sequence const_pointer as common type to compare pointers. Add a + fallback overload in case pointers cannot be cast to sequence + const_pointer. + * testsuite/23_containers/vector/modifiers/insert/58148.cc: New. + +2013-08-30 François Dumont + PR libstdc++/58191 * include/debug/macros.h (__glibcxx_check_partitioned_lower): Add __gnu_debug::__base calls on iterators passed to internal debug diff --git a/libstdc++-v3/include/debug/functions.h b/libstdc++-v3/include/debug/functions.h index 650793065c3..8e76b7f2ee5 100644 --- a/libstdc++-v3/include/debug/functions.h +++ b/libstdc++-v3/include/debug/functions.h @@ -36,7 +36,7 @@ #include // for __addressof and addressof #if __cplusplus >= 201103L # include // for less and greater_equal -# include // for common_type +# include // for is_lvalue_reference and __and_ #endif #include @@ -172,27 +172,30 @@ namespace __gnu_debug } #if __cplusplus >= 201103L - template + // Default implementation. + template inline bool __foreign_iterator_aux4(const _Safe_iterator<_Iterator, _Sequence>& __it, - _InputIterator __other, - _PointerType1, _PointerType2) + typename _Sequence::const_pointer __begin, + typename _Sequence::const_pointer __other) { - 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()))) - || __ge(std::addressof(*__other), - std::addressof(*(__it._M_get_sequence()->_M_base().end() - - 1)) + 1)); + return (__l(__other, __begin) + || __l(std::addressof(*(__it._M_get_sequence()->_M_base().end() + - 1)), __other)); } - + + // Fallback when address type cannot be implicitely casted to sequence + // const_pointer. + template + inline bool + __foreign_iterator_aux4(const _Safe_iterator<_Iterator, _Sequence>&, + _InputIterator, ...) + { return true; } + template inline bool __foreign_iterator_aux3(const _Safe_iterator<_Iterator, _Sequence>& __it, @@ -209,7 +212,7 @@ namespace __gnu_debug - std::addressof(*(__it._M_get_sequence()->_M_base().begin())) == __it._M_get_sequence()->size() - 1) return (__foreign_iterator_aux4 - (__it, __other, + (__it, std::addressof(*(__it._M_get_sequence()->_M_base().begin())), std::addressof(*__other))); return true; @@ -223,7 +226,7 @@ namespace __gnu_debug std::false_type) { return true; } #endif - + /** Checks that iterators do not belong to the same sequence. */ template inline bool diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/insert/58148.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/insert/58148.cc new file mode 100644 index 00000000000..bfb2c0959c8 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/insert/58148.cc @@ -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 +// . + +// { dg-options "-std=gnu++11" } +// { dg-do compile } + +#include + +void +test01() +{ + std::vector v; + char c = 'a'; + v.insert(v.begin(), &c, &c); +} + +int main() +{ + test01(); + return 0; +} -- 2.11.4.GIT