gcc/
[official-gcc.git] / libstdc++-v3 / testsuite / 28_regex / regression.cc
blobefc9c64fcee144e36583c0008b4d0b1634a41456
1 // { dg-do run { target c++11 } }
3 //
4 // Copyright (C) 2015-2018 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.
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/>.
21 #include <testsuite_hooks.h>
22 #include <testsuite_regex.h>
24 using namespace __gnu_test;
25 using namespace std;
27 // PR libstdc++/67362
28 void
29 test01()
31 regex re("((.)", regex_constants::basic);
34 void
35 test02()
37 std::string re_str
39 "/abcd" "\n"
40 "/aecf" "\n"
41 "/ghci"
43 auto rx = std::regex(re_str, std::regex_constants::grep | std::regex_constants::icase);
44 VERIFY(regex_search_debug("/abcd", rx));
47 void
48 test03()
50 VERIFY(regex_match_debug("a.", regex(R"(a\b.)"), regex_constants::match_not_eow));
51 VERIFY(regex_match_debug(".a", regex(R"(.\ba)"), regex_constants::match_not_bow));
52 VERIFY(regex_search_debug("a", regex(R"(^\b)")));
53 VERIFY(regex_search_debug("a", regex(R"(\b$)")));
54 VERIFY(!regex_search_debug("a", regex(R"(^\b)"), regex_constants::match_not_bow));
55 VERIFY(!regex_search_debug("a", regex(R"(\b$)"), regex_constants::match_not_eow));
58 // PR libstdc++/77356
59 void
60 test04()
62 static const char* kNumericAnchor ="(\\$|usd)(usd|\\$|to|and|up to|[0-9,\\.\\-\\sk])+";
63 const std::regex re(kNumericAnchor);
64 (void)re;
67 void
68 test05()
70 VERIFY(regex_match_debug("!", std::regex("[![:alnum:]]")));
71 VERIFY(regex_match_debug("-", std::regex("[a-]", regex_constants::basic)));
72 VERIFY(regex_match_debug("-", std::regex("[a-]")));
75 // PR libstdc++/78236
76 void
77 test06()
79 char const s[] = "afoo";
80 std::basic_regex<char> r("(f+)");
82 std::cregex_iterator i(s, s+sizeof(s), r);
83 std::cregex_iterator j(s, s+sizeof(s), r);
84 VERIFY(i == j);
86 // The iterator manipulation code must be repeated in the same scope
87 // to expose the undefined read during the execution of the ==
88 // operator (stack location reuse)
90 std::cregex_iterator i(s, s+sizeof(s), r);
91 std::cregex_iterator j;
92 VERIFY(!(i == j));
96 // PR libstdc++/71500
97 void
98 test07()
100 bool test [[gnu::unused]] = true;
102 VERIFY(regex_match_debug("abc abc", regex("([a-z]+) \\1", regex::icase)));
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)));
108 main()
110 test01();
111 test02();
112 test03();
113 test04();
114 test05();
115 test06();
116 test07();
117 return 0;