| 1 | // { dg-do run { target c++11 } } |
| 2 | // { dg-timeout-factor 2 } |
| 3 | |
| 4 | // Copyright (C) 2015-2025 Free Software Foundation, Inc. |
| 5 | // |
| 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) |
| 10 | // any later version. |
| 11 | // |
| 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. |
| 16 | // |
| 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/>. |
| 20 | |
| 21 | #include <regex> |
| 22 | #include <testsuite_hooks.h> |
| 23 | #include <testsuite_regex.h> |
| 24 | |
| 25 | using namespace std; |
| 26 | using namespace __gnu_test; |
| 27 | |
| 28 | // libstdc++/64441 |
| 29 | void |
| 30 | test01() |
| 31 | { |
| 32 | const char s[] = "abc"; |
| 33 | const std::regex re("(\\d+)|(\\w+)"); |
| 34 | |
| 35 | std::cmatch m; |
| 36 | VERIFY(regex_search_debug(s, m, re)); |
| 37 | |
| 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), |
| 43 | }; |
| 44 | for (size_t i = 0, n = m.size(); i <= n; ++i) { |
| 45 | auto&& sub = m[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])); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | // libstdc++/64781 |
| 54 | void |
| 55 | test02() |
| 56 | { |
| 57 | std::match_results<const char*> m; |
| 58 | const char s[] = "a"; |
| 59 | VERIFY(regex_search_debug(s, m, std::regex("a"))); |
| 60 | |
| 61 | VERIFY(m.size() == 1); |
| 62 | |
| 63 | VERIFY(m[0].first == s+0); |
| 64 | VERIFY(m[0].second == s+1); |
| 65 | VERIFY(m[0].matched == true); |
| 66 | |
| 67 | VERIFY(m[42].first == s+1); |
| 68 | VERIFY(m[42].second == s+1); |
| 69 | VERIFY(m[42].matched == false); |
| 70 | } |
| 71 | |
| 72 | int |
| 73 | main() |
| 74 | { |
| 75 | test01(); |
| 76 | test02(); |
| 77 | return 0; |
| 78 | } |