Skip to content

Commit b22b732

Browse files
author
redi
committed
PR libstdc++/71500 restore C++11 compatibility in <regex>
PR libstdc++/71500 * include/bits/regex_executor.tcc (_Backref_matcher<BidIt, regex_traits<C>>::_M_apply): Use std::__equal4 instead of C++14 4-iterator overloads of std::equal. * include/bits/stl_algobase.h (__equal4): New functions implementing 4-iterator overloads of std::equal for use in C++11. (equal(It1, It1, It2, It2), equal(It1, It1, It2, It2, BinaryPred)): Move function bodies to new __equal4 functions. * testsuite/28_regex/simple_c++11.cc: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@252981 138bc75d-0d04-0410-961f-82ee72b054a4
1 parent 103be9b commit b22b732

File tree

4 files changed

+105
-48
lines changed

4 files changed

+105
-48
lines changed

libstdc++-v3/ChangeLog

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
2017-09-19 Jonathan Wakely <[email protected]>
22

3+
PR libstdc++/71500
4+
* include/bits/regex_executor.tcc
5+
(_Backref_matcher<BidIt, regex_traits<C>>::_M_apply): Use
6+
std::__equal4 instead of C++14 4-iterator overloads of std::equal.
7+
* include/bits/stl_algobase.h (__equal4): New functions implementing
8+
4-iterator overloads of std::equal for use in C++11.
9+
(equal(It1, It1, It2, It2), equal(It1, It1, It2, It2, BinaryPred)):
10+
Move function bodies to new __equal4 functions.
11+
* testsuite/28_regex/simple_c++11.cc: New.
12+
313
PR libstdc++/82254
414
* include/std/type_traits (__is_invocable): Add partial specialization
515
for INVOKE<void> case and remove is_void<R> check from partial
@@ -356,7 +366,7 @@
356366
2017-09-11 Tim Shen <[email protected]>
357367

358368
PR libstdc++/71500
359-
* include/bits/regex_executor.tcc: Support icase in regex_tratis<...>
369+
* include/bits/regex_executor.tcc: Support icase in regex_traits<...>
360370
for back reference matches.
361371
* testsuite/28_regex/regression.cc: Test case.
362372

libstdc++-v3/include/bits/regex_executor.tcc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -366,17 +366,17 @@ namespace __detail
366366
_BiIter __actual_end)
367367
{
368368
if (!_M_icase)
369-
return std::equal(__expected_begin, __expected_end,
370-
__actual_begin, __actual_end);
369+
return std::__equal4(__expected_begin, __expected_end,
370+
__actual_begin, __actual_end);
371371
typedef std::ctype<_CharT> __ctype_type;
372372
const auto& __fctyp = use_facet<__ctype_type>(_M_traits.getloc());
373-
return std::equal(__expected_begin, __expected_end,
374-
__actual_begin, __actual_end,
375-
[this, &__fctyp](_CharT __lhs, _CharT __rhs)
376-
{
377-
return __fctyp.tolower(__lhs)
378-
== __fctyp.tolower(__rhs);
379-
});
373+
return std::__equal4(__expected_begin, __expected_end,
374+
__actual_begin, __actual_end,
375+
[this, &__fctyp](_CharT __lhs, _CharT __rhs)
376+
{
377+
return __fctyp.tolower(__lhs)
378+
== __fctyp.tolower(__rhs);
379+
});
380380
}
381381

382382
bool _M_icase;

libstdc++-v3/include/bits/stl_algobase.h

Lines changed: 58 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,60 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
10821082
return true;
10831083
}
10841084

1085+
#if __cplusplus >= 201103L
1086+
// 4-iterator version of std::equal<It1, It2> for use in C++11.
1087+
template<typename _II1, typename _II2>
1088+
inline bool
1089+
__equal4(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1090+
{
1091+
using _RATag = random_access_iterator_tag;
1092+
using _Cat1 = typename iterator_traits<_II1>::iterator_category;
1093+
using _Cat2 = typename iterator_traits<_II2>::iterator_category;
1094+
using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1095+
if (_RAIters())
1096+
{
1097+
auto __d1 = std::distance(__first1, __last1);
1098+
auto __d2 = std::distance(__first2, __last2);
1099+
if (__d1 != __d2)
1100+
return false;
1101+
return _GLIBCXX_STD_A::equal(__first1, __last1, __first2);
1102+
}
1103+
1104+
for (; __first1 != __last1 && __first2 != __last2;
1105+
++__first1, (void)++__first2)
1106+
if (!(*__first1 == *__first2))
1107+
return false;
1108+
return __first1 == __last1 && __first2 == __last2;
1109+
}
1110+
1111+
// 4-iterator version of std::equal<It1, It2, BinaryPred> for use in C++11.
1112+
template<typename _II1, typename _II2, typename _BinaryPredicate>
1113+
inline bool
1114+
__equal4(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2,
1115+
_BinaryPredicate __binary_pred)
1116+
{
1117+
using _RATag = random_access_iterator_tag;
1118+
using _Cat1 = typename iterator_traits<_II1>::iterator_category;
1119+
using _Cat2 = typename iterator_traits<_II2>::iterator_category;
1120+
using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1121+
if (_RAIters())
1122+
{
1123+
auto __d1 = std::distance(__first1, __last1);
1124+
auto __d2 = std::distance(__first2, __last2);
1125+
if (__d1 != __d2)
1126+
return false;
1127+
return _GLIBCXX_STD_A::equal(__first1, __last1, __first2,
1128+
__binary_pred);
1129+
}
1130+
1131+
for (; __first1 != __last1 && __first2 != __last2;
1132+
++__first1, (void)++__first2)
1133+
if (!bool(__binary_pred(*__first1, *__first2)))
1134+
return false;
1135+
return __first1 == __last1 && __first2 == __last2;
1136+
}
1137+
#endif // C++11
1138+
10851139
#if __cplusplus > 201103L
10861140

10871141
#define __cpp_lib_robust_nonmodifying_seq_ops 201304
@@ -1112,24 +1166,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
11121166
__glibcxx_requires_valid_range(__first1, __last1);
11131167
__glibcxx_requires_valid_range(__first2, __last2);
11141168

1115-
using _RATag = random_access_iterator_tag;
1116-
using _Cat1 = typename iterator_traits<_II1>::iterator_category;
1117-
using _Cat2 = typename iterator_traits<_II2>::iterator_category;
1118-
using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1119-
if (_RAIters())
1120-
{
1121-
auto __d1 = std::distance(__first1, __last1);
1122-
auto __d2 = std::distance(__first2, __last2);
1123-
if (__d1 != __d2)
1124-
return false;
1125-
return _GLIBCXX_STD_A::equal(__first1, __last1, __first2);
1126-
}
1127-
1128-
for (; __first1 != __last1 && __first2 != __last2;
1129-
++__first1, (void)++__first2)
1130-
if (!(*__first1 == *__first2))
1131-
return false;
1132-
return __first1 == __last1 && __first2 == __last2;
1169+
return _GLIBCXX_STD_A::__equal4(__first1, __last1, __first2, __last2);
11331170
}
11341171

11351172
/**
@@ -1159,27 +1196,10 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
11591196
__glibcxx_requires_valid_range(__first1, __last1);
11601197
__glibcxx_requires_valid_range(__first2, __last2);
11611198

1162-
using _RATag = random_access_iterator_tag;
1163-
using _Cat1 = typename iterator_traits<_IIter1>::iterator_category;
1164-
using _Cat2 = typename iterator_traits<_IIter2>::iterator_category;
1165-
using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1166-
if (_RAIters())
1167-
{
1168-
auto __d1 = std::distance(__first1, __last1);
1169-
auto __d2 = std::distance(__first2, __last2);
1170-
if (__d1 != __d2)
1171-
return false;
1172-
return _GLIBCXX_STD_A::equal(__first1, __last1, __first2,
1173-
__binary_pred);
1174-
}
1175-
1176-
for (; __first1 != __last1 && __first2 != __last2;
1177-
++__first1, (void)++__first2)
1178-
if (!bool(__binary_pred(*__first1, *__first2)))
1179-
return false;
1180-
return __first1 == __last1 && __first2 == __last2;
1199+
return _GLIBCXX_STD_A::__equal4(__first1, __last1, __first2, __last2,
1200+
__binary_pred);
11811201
}
1182-
#endif
1202+
#endif // C++14
11831203

11841204
/**
11851205
* @brief Performs @b dictionary comparison on ranges.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (C) 2017 Free Software Foundation, Inc.
2+
//
3+
// This file is part of the GNU ISO C++ Library. This library is free
4+
// software; you can redistribute it and/or modify it under the
5+
// terms of the GNU General Public License as published by the
6+
// Free Software Foundation; either version 3, or (at your option)
7+
// any later version.
8+
9+
// This library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License along
15+
// with this library; see the file COPYING3. If not see
16+
// <http://www.gnu.org/licenses/>.
17+
18+
// { dg-options "-std=gnu++11" }
19+
// { dg-do compile }
20+
21+
#include <regex>
22+
23+
// Ensure compilation of trivial example still works with C++11.
24+
// https://gcc.gnu.org/ml/libstdc++/2017-09/msg00040.html
25+
std::regex r{""};
26+
std::cmatch m;
27+
bool b = regex_match("", m, r);

0 commit comments

Comments
 (0)