1 // { dg-do run { target c++11 } }
2 // { dg-timeout-factor 2 }
5 // Copyright (C) 2015-2025 Free Software Foundation, Inc.
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
22 #include <testsuite_hooks.h>
23 #include <testsuite_regex.h>
25 using namespace __gnu_test
;
32 regex
re("((.)", regex_constants::basic
);
44 auto rx
= std::regex(re_str
, std::regex_constants::grep
| std::regex_constants::icase
);
45 VERIFY(regex_search_debug("/abcd", rx
));
51 VERIFY(regex_match_debug("a.", regex(R
"(a\b.)"), regex_constants::match_not_eow
));
52 VERIFY(regex_match_debug(".a", regex(R
"(.\ba)"), regex_constants::match_not_bow
));
53 VERIFY(regex_search_debug("a", regex(R
"(^\b)")));
54 VERIFY(regex_search_debug("a", regex(R
"(\b$)")));
55 VERIFY(!regex_search_debug("a", regex(R
"(^\b)"), regex_constants::match_not_bow
));
56 VERIFY(!regex_search_debug("a", regex(R
"(\b$)"), regex_constants::match_not_eow
));
63 static const char* kNumericAnchor
="(\\$|usd)(usd|\\$|to|and|up to|[0-9,\\.\\-\\sk])+";
64 const std::regex
re(kNumericAnchor
);
71 VERIFY(regex_match_debug("!", std::regex("[![:alnum:]]")));
72 VERIFY(regex_match_debug("-", std::regex("[a-]", regex_constants::basic
)));
73 VERIFY(regex_match_debug("-", std::regex("[a-]")));
80 char const s
[] = "afoo";
81 std::basic_regex
<char> r("(f+)");
83 std::cregex_iterator
i(s
, s
+sizeof(s
), r
);
84 std::cregex_iterator
j(s
, s
+sizeof(s
), r
);
87 // The iterator manipulation code must be repeated in the same scope
88 // to expose the undefined read during the execution of the ==
89 // operator (stack location reuse)
91 std::cregex_iterator
i(s
, s
+sizeof(s
), r
);
92 std::cregex_iterator j
;
101 bool test
[[gnu::unused
]] = true;
103 VERIFY(regex_match_debug("abc abc", regex("([a-z]+) \\1", regex::icase
)));
104 VERIFY(regex_match_debug("Abc abc", regex("([a-z]+) \\1", regex::icase
)));
105 VERIFY(regex_match_debug("abc Abc", regex("([a-z]+) \\1", regex::icase
)));