]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/28_regex/match_results/out_of_range_submatches.cc
1 // { dg-do run { target c++11 } }
2 // { dg-timeout-factor 2 }
4 // Copyright (C) 2015-2020 Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
22 #include <testsuite_hooks.h>
23 #include <testsuite_regex.h>
26 using namespace __gnu_test
;
32 const char s
[] = "abc";
33 const std::regex
re("(\\d+)|(\\w+)");
36 VERIFY(regex_search_debug(s
, m
, re
));
38 std::tuple
<bool, string
, int, int> expected
[] = {
39 make_tuple(true, "abc", 0, 3),
40 make_tuple(false, "", 3, 3),
41 make_tuple(true, "abc", 0, 3),
42 make_tuple(false, "", 3, 3),
44 for (size_t i
= 0, n
= m
.size(); i
<= n
; ++i
) {
46 VERIFY(sub
.matched
== std::get
<0>(expected
[i
]));
47 VERIFY(sub
.str() == std::get
<1>(expected
[i
]));
48 VERIFY((sub
.first
- s
) == std::get
<2>(expected
[i
]));
49 VERIFY((sub
.second
- s
) == std::get
<3>(expected
[i
]));
57 std::match_results
<const char*> m
;
59 VERIFY(regex_search_debug(s
, m
, std::regex("a")));
61 VERIFY(m
.size() == 1);
63 VERIFY(m
[0].first
== s
+0);
64 VERIFY(m
[0].second
== s
+1);
65 VERIFY(m
[0].matched
== true);
67 VERIFY(m
[42].first
== s
+1);
68 VERIFY(m
[42].second
== s
+1);
69 VERIFY(m
[42].matched
== false);