111
|
1 // { dg-do run { target c++11 } }
|
|
2
|
|
3 //
|
131
|
4 // Copyright (C) 2015-2018 Free Software Foundation, Inc.
|
111
|
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 <testsuite_hooks.h>
|
|
22 #include <testsuite_regex.h>
|
|
23
|
|
24 using namespace __gnu_test;
|
|
25 using namespace std;
|
|
26
|
|
27 // PR libstdc++/67362
|
|
28 void
|
|
29 test01()
|
|
30 {
|
|
31 regex re("((.)", regex_constants::basic);
|
|
32 }
|
|
33
|
|
34 void
|
|
35 test02()
|
|
36 {
|
|
37 std::string re_str
|
|
38 {
|
|
39 "/abcd" "\n"
|
|
40 "/aecf" "\n"
|
|
41 "/ghci"
|
|
42 };
|
|
43 auto rx = std::regex(re_str, std::regex_constants::grep | std::regex_constants::icase);
|
|
44 VERIFY(regex_search_debug("/abcd", rx));
|
|
45 }
|
|
46
|
|
47 void
|
|
48 test03()
|
|
49 {
|
|
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));
|
|
56 }
|
|
57
|
|
58 // PR libstdc++/77356
|
|
59 void
|
|
60 test04()
|
|
61 {
|
|
62 static const char* kNumericAnchor ="(\\$|usd)(usd|\\$|to|and|up to|[0-9,\\.\\-\\sk])+";
|
|
63 const std::regex re(kNumericAnchor);
|
|
64 (void)re;
|
|
65 }
|
|
66
|
|
67 void
|
|
68 test05()
|
|
69 {
|
|
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-]")));
|
|
73 }
|
|
74
|
|
75 // PR libstdc++/78236
|
|
76 void
|
|
77 test06()
|
|
78 {
|
|
79 char const s[] = "afoo";
|
|
80 std::basic_regex<char> r("(f+)");
|
|
81 {
|
|
82 std::cregex_iterator i(s, s+sizeof(s), r);
|
|
83 std::cregex_iterator j(s, s+sizeof(s), r);
|
|
84 VERIFY(i == j);
|
|
85 }
|
|
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)
|
|
89 {
|
|
90 std::cregex_iterator i(s, s+sizeof(s), r);
|
|
91 std::cregex_iterator j;
|
|
92 VERIFY(!(i == j));
|
|
93 }
|
|
94 }
|
|
95
|
|
96 // PR libstdc++/71500
|
|
97 void
|
|
98 test07()
|
|
99 {
|
|
100 bool test [[gnu::unused]] = true;
|
|
101
|
|
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)));
|
|
105 }
|
|
106
|
|
107 int
|
|
108 main()
|
|
109 {
|
|
110 test01();
|
|
111 test02();
|
|
112 test03();
|
|
113 test04();
|
|
114 test05();
|
|
115 test06();
|
|
116 test07();
|
|
117 return 0;
|
|
118 }
|
|
119
|