From 84a9d3b6c1f1de2aa6b5bef700f51b2e7c0bc600 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fran=C3=A7ois=20Dumont?= Date: Tue, 12 Jun 2018 20:18:35 +0000 Subject: [PATCH] macros.h (__glibcxx_check_can_increment_range): New. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 2018-06-12 François Dumont * include/debug/macros.h (__glibcxx_check_can_increment_range): New. (__glibcxx_check_can_decrement_range): New. * include/debug/debug.h (__glibcxx_requires_can_increment_range): New. (__glibcxx_requires_can_decrement_range): New. * include/bits/stl_algobase.h (std::copy(_II, _II, _OI)): Use __glibcxx_requires_can_increment_range. (std::move(_II, _II, _OI)): Likewise. (std::copy_backward(_BI, _BI, _BI2)): Use __glibcxx_requires_can_decrement_range. (std::move_backward(_BI, _BI, _BI2)): Likewise. * testsuite/25_algorithms/copy_backward/debug/1_neg.cc: New. * testsuite/25_algorithms/copy_backward/debug/2_neg.cc: New. * testsuite/25_algorithms/copy_backward/debug/3_neg.cc: New. * testsuite/25_algorithms/equal/debug/1_neg.cc: New. * testsuite/25_algorithms/equal/debug/2_neg.cc: New. * testsuite/25_algorithms/equal/debug/3_neg.cc: New. From-SVN: r261525 --- libstdc++-v3/ChangeLog | 19 ++++++++ libstdc++-v3/include/bits/stl_algobase.h | 18 ++++--- libstdc++-v3/include/debug/macros.h | 47 +++++++++++++++++-- .../copy_backward/debug/1_neg.cc | 37 +++++++++++++++ .../copy_backward/debug/2_neg.cc | 37 +++++++++++++++ .../copy_backward/debug/3_neg.cc | 41 ++++++++++++++++ .../25_algorithms/equal/debug/1_neg.cc | 37 +++++++++++++++ .../25_algorithms/equal/debug/2_neg.cc | 37 +++++++++++++++ .../25_algorithms/equal/debug/3_neg.cc | 43 +++++++++++++++++ 9 files changed, 302 insertions(+), 14 deletions(-) create mode 100644 libstdc++-v3/testsuite/25_algorithms/copy_backward/debug/1_neg.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/copy_backward/debug/2_neg.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/copy_backward/debug/3_neg.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/equal/debug/1_neg.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/equal/debug/2_neg.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/equal/debug/3_neg.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 368a91ebf33..813e7d2f966 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,22 @@ +2018-06-12 François Dumont + + * include/debug/macros.h (__glibcxx_check_can_increment_range): New. + (__glibcxx_check_can_decrement_range): New. + * include/debug/debug.h (__glibcxx_requires_can_increment_range): New. + (__glibcxx_requires_can_decrement_range): New. + * include/bits/stl_algobase.h (std::copy(_II, _II, _OI)): Use + __glibcxx_requires_can_increment_range. + (std::move(_II, _II, _OI)): Likewise. + (std::copy_backward(_BI, _BI, _BI2)): Use + __glibcxx_requires_can_decrement_range. + (std::move_backward(_BI, _BI, _BI2)): Likewise. + * testsuite/25_algorithms/copy_backward/debug/1_neg.cc: New. + * testsuite/25_algorithms/copy_backward/debug/2_neg.cc: New. + * testsuite/25_algorithms/copy_backward/debug/3_neg.cc: New. + * testsuite/25_algorithms/equal/debug/1_neg.cc: New. + * testsuite/25_algorithms/equal/debug/2_neg.cc: New. + * testsuite/25_algorithms/equal/debug/3_neg.cc: New. + 2018-06-12 Jonathan Wakely P0935R0 Eradicating unnecessarily explicit default constructors diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index 1fcd7dba34d..877f32b0053 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -449,11 +449,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __glibcxx_function_requires(_InputIteratorConcept<_II>) __glibcxx_function_requires(_OutputIteratorConcept<_OI, typename iterator_traits<_II>::value_type>) - __glibcxx_requires_valid_range(__first, __last); + __glibcxx_requires_can_increment_range(__first, __last, __result); - return (std::__copy_move_a2<__is_move_iterator<_II>::__value> - (std::__miter_base(__first), std::__miter_base(__last), - __result)); + return std::__copy_move_a2<__is_move_iterator<_II>::__value> + (std::__miter_base(__first), std::__miter_base(__last), __result); } #if __cplusplus >= 201103L @@ -482,7 +481,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __glibcxx_function_requires(_InputIteratorConcept<_II>) __glibcxx_function_requires(_OutputIteratorConcept<_OI, typename iterator_traits<_II>::value_type>) - __glibcxx_requires_valid_range(__first, __last); + __glibcxx_requires_can_increment_range(__first, __last, __result); return std::__copy_move_a2(std::__miter_base(__first), std::__miter_base(__last), __result); @@ -627,11 +626,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __glibcxx_function_requires(_ConvertibleConcept< typename iterator_traits<_BI1>::value_type, typename iterator_traits<_BI2>::value_type>) - __glibcxx_requires_valid_range(__first, __last); + __glibcxx_requires_can_decrement_range(__first, __last, __result); - return (std::__copy_move_backward_a2<__is_move_iterator<_BI1>::__value> - (std::__miter_base(__first), std::__miter_base(__last), - __result)); + return std::__copy_move_backward_a2<__is_move_iterator<_BI1>::__value> + (std::__miter_base(__first), std::__miter_base(__last), __result); } #if __cplusplus >= 201103L @@ -663,7 +661,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __glibcxx_function_requires(_ConvertibleConcept< typename iterator_traits<_BI1>::value_type, typename iterator_traits<_BI2>::value_type>) - __glibcxx_requires_valid_range(__first, __last); + __glibcxx_requires_can_decrement_range(__first, __last, __result); return std::__copy_move_backward_a2(std::__miter_base(__first), std::__miter_base(__last), diff --git a/libstdc++-v3/include/debug/macros.h b/libstdc++-v3/include/debug/macros.h index 824d399941c..a88faf96e65 100644 --- a/libstdc++-v3/include/debug/macros.h +++ b/libstdc++-v3/include/debug/macros.h @@ -38,12 +38,15 @@ * the user error and where the error is reported. * */ +#define _GLIBCXX_DEBUG_VERIFY_COND_AT(_Cond,_ErrMsg,_File,_Line,_Func) \ + if (! (_Cond)) \ + __gnu_debug::_Error_formatter::_S_at(_File, _Line, _Func) \ + ._ErrMsg._M_error() + #define _GLIBCXX_DEBUG_VERIFY_AT_F(_Cond,_ErrMsg,_File,_Line,_Func) \ do \ { \ - if (! (_Cond)) \ - __gnu_debug::_Error_formatter::_S_at(_File, _Line, _Func) \ - ._ErrMsg._M_error(); \ + _GLIBCXX_DEBUG_VERIFY_COND_AT(_Cond,_ErrMsg,_File,_Line,_Func); \ } while (false) #define _GLIBCXX_DEBUG_VERIFY_AT(_Cond,_ErrMsg,_File,_Line) \ @@ -84,6 +87,42 @@ _GLIBCXX_DEBUG_VERIFY(_First != _Last, \ ._M_iterator(_First, #_First) \ ._M_iterator(_Last, #_Last)) +#define __glibcxx_check_can_increment_range(_First1,_Last1,_First2) \ + do \ + { \ + typename __gnu_debug::_Distance_traits<__decltype(_First1)>::__type __dist;\ + _GLIBCXX_DEBUG_VERIFY_COND_AT( \ + __gnu_debug::__valid_range(_First1, _Last1, __dist),\ + _M_message(__gnu_debug::__msg_valid_range) \ + ._M_iterator(_First1, #_First1) \ + ._M_iterator(_Last1, #_Last1), \ + __FILE__,__LINE__,__PRETTY_FUNCTION__); \ + _GLIBCXX_DEBUG_VERIFY_COND_AT( \ + __gnu_debug::__can_advance(_First2, __dist.first),\ + _M_message(__gnu_debug::__msg_iter_subscript_oob)\ + ._M_iterator(_First2, #_First2) \ + ._M_integer(__dist.first), \ + __FILE__,__LINE__,__PRETTY_FUNCTION__); \ + } while(false) + +#define __glibcxx_check_can_decrement_range(_First1,_Last1,_First2) \ + do \ + { \ + typename __gnu_debug::_Distance_traits<__decltype(_First1)>::__type __dist;\ + _GLIBCXX_DEBUG_VERIFY_COND_AT( \ + __gnu_debug::__valid_range(_First1, _Last1, __dist),\ + _M_message(__gnu_debug::__msg_valid_range) \ + ._M_iterator(_First1, #_First1) \ + ._M_iterator(_Last1, #_Last1), \ + __FILE__,__LINE__,__PRETTY_FUNCTION__); \ + _GLIBCXX_DEBUG_VERIFY_COND_AT( \ + __gnu_debug::__can_advance(_First2, -__dist.first),\ + _M_message(__gnu_debug::__msg_iter_subscript_oob)\ + ._M_iterator(_First2, #_First2) \ + ._M_integer(-__dist.first), \ + __FILE__,__LINE__,__PRETTY_FUNCTION__); \ + } while(false) + /** Verify that we can insert into *this with the iterator _Position. * Insertion into a container at a specific position requires that * the iterator be nonsingular, either dereferenceable or past-the-end, @@ -145,7 +184,7 @@ _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__foreign_iterator(_Position,_First,_Last),\ * _Safe_sequence and the _Position iterator is a _Safe_iterator. */ #define __glibcxx_check_insert_range_after(_Position,_First,_Last,_Dist)\ - __glibcxx_check_valid_range2(_First,_Last,_Dist); \ +__glibcxx_check_valid_range2(_First,_Last,_Dist); \ __glibcxx_check_insert_after(_Position); \ _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__foreign_iterator(_Position,_First,_Last),\ _M_message(__gnu_debug::__msg_insert_range_from_self)\ diff --git a/libstdc++-v3/testsuite/25_algorithms/copy_backward/debug/1_neg.cc b/libstdc++-v3/testsuite/25_algorithms/copy_backward/debug/1_neg.cc new file mode 100644 index 00000000000..10375b75bf5 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy_backward/debug/1_neg.cc @@ -0,0 +1,37 @@ +// Copyright (C) 2018 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-do run { xfail *-*-* } } +// { dg-require-debug-mode "" } + +#include +#include + +void +test01() +{ + std::vector vect; + vect.push_back(1); + std::copy_backward(vect.end(), vect.begin(), vect.end()); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/copy_backward/debug/2_neg.cc b/libstdc++-v3/testsuite/25_algorithms/copy_backward/debug/2_neg.cc new file mode 100644 index 00000000000..7f6bcd1ec2e --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy_backward/debug/2_neg.cc @@ -0,0 +1,37 @@ +// Copyright (C) 2018 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-do run { xfail *-*-* } } +// { dg-require-debug-mode "" } + +#include +#include + +void +test01() +{ + std::vector vect; + vect.push_back(1); + std::copy_backward(vect.begin(), vect.end(), vect.begin()); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/copy_backward/debug/3_neg.cc b/libstdc++-v3/testsuite/25_algorithms/copy_backward/debug/3_neg.cc new file mode 100644 index 00000000000..89d5d0a94e7 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy_backward/debug/3_neg.cc @@ -0,0 +1,41 @@ +// Copyright (C) 2018 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-do run { xfail *-*-* } } +// { dg-require-debug-mode "" } + +#include +#include + +void +test01() +{ + std::list l1, l2; + l1.push_back(1); + l1.push_back(2); + l1.push_back(3); + + l2.push_back(1); + std::copy_backward(++l1.begin(), l1.end(), l2.end()); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/equal/debug/1_neg.cc b/libstdc++-v3/testsuite/25_algorithms/equal/debug/1_neg.cc new file mode 100644 index 00000000000..096c785e283 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/equal/debug/1_neg.cc @@ -0,0 +1,37 @@ +// Copyright (C) 2018 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-do run { xfail *-*-* } } +// { dg-require-debug-mode "" } + +#include +#include + +void +test01() +{ + std::vector vect; + vect.push_back(1); + std::equal(vect.end(), vect.begin(), vect.begin()); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/equal/debug/2_neg.cc b/libstdc++-v3/testsuite/25_algorithms/equal/debug/2_neg.cc new file mode 100644 index 00000000000..97b1e1faa0b --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/equal/debug/2_neg.cc @@ -0,0 +1,37 @@ +// Copyright (C) 2018 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-do run { xfail *-*-* } } +// { dg-require-debug-mode "" } + +#include +#include + +void +test01() +{ + std::vector v1, v2; + v1.push_back(1); + std::equal(v1.begin(), v1.end(), v2.begin()); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/equal/debug/3_neg.cc b/libstdc++-v3/testsuite/25_algorithms/equal/debug/3_neg.cc new file mode 100644 index 00000000000..48bcea7e7ae --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/equal/debug/3_neg.cc @@ -0,0 +1,43 @@ +// Copyright (C) 2018 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-do run { xfail *-*-* } } +// { dg-require-debug-mode "" } + +#include +#include + +void +test01() +{ + std::list l1, l2; + l1.push_back(1); + l1.push_back(2); + l1.push_back(3); + + l2.push_back(1); + l2.push_back(2); + + std::equal(++l1.begin(), l1.end(), ++l2.begin()); +} + +int +main() +{ + test01(); + return 0; +} -- 2.30.2