| 1 | // { dg-do run { target c++11 } } |
| 2 | #include <regex> |
| 3 | #include <testsuite_hooks.h> |
| 4 | |
| 5 | #if __cplusplus >= 201703L || !defined __STRICT_ANSI__ |
| 6 | static_assert( std::regex_constants::multiline == std::regex::multiline ); |
| 7 | static_assert( std::regex_constants::__multiline == std::regex::multiline ); |
| 8 | #else |
| 9 | namespace test { constexpr int multiline = 0; } |
| 10 | namespace check { |
| 11 | using namespace test; |
| 12 | using namespace std::regex_constants; |
| 13 | int ml = multiline; |
| 14 | } |
| 15 | #endif |
| 16 | |
| 17 | void |
| 18 | test01() |
| 19 | { |
| 20 | using namespace std::regex_constants; |
| 21 | |
| 22 | std::regex ml{"^a.$", __multiline}; |
| 23 | VERIFY( ml.flags() == __multiline ); |
| 24 | VERIFY(!std::regex_search("abx\nxab", ml)); |
| 25 | VERIFY(std::regex_search("x\nab", ml)); |
| 26 | VERIFY(std::regex_search("ab\n", ml)); |
| 27 | VERIFY(std::regex_search("x\nab\nx", ml)); |
| 28 | |
| 29 | ml.assign("a$\n^b$\n^c", ECMAScript|__multiline); |
| 30 | VERIFY( ml.flags() == ECMAScript|__multiline ); |
| 31 | VERIFY( regex_search("a\nb\nc", ml) ); |
| 32 | |
| 33 | ml.assign("a$\n^b$\n^c", ECMAScript|__multiline|icase); |
| 34 | VERIFY( ml.flags() == ECMAScript|__multiline|icase ); |
| 35 | VERIFY( regex_search("A\nB\nC", ml) ); |
| 36 | } |
| 37 | |
| 38 | void |
| 39 | test_pr102480() |
| 40 | { |
| 41 | using namespace std::regex_constants; |
| 42 | |
| 43 | std::regex re("^a"); |
| 44 | std::regex reml("^a", __multiline); |
| 45 | VERIFY( std::regex_match("\na" + 1, re)); |
| 46 | VERIFY( std::regex_match("\na" + 1, reml)); |
| 47 | // PR libstdc++/102480 |
| 48 | VERIFY(!std::regex_match("\na" + 1, re, match_prev_avail)); |
| 49 | VERIFY( std::regex_match("\na" + 1, reml, match_prev_avail)); |
| 50 | VERIFY(!std::regex_match("\na" + 1, re, match_not_bol)); |
| 51 | VERIFY(!std::regex_match("\na" + 1, re, match_prev_avail|match_not_bol)); |
| 52 | VERIFY( std::regex_match("\na" + 1, reml, match_prev_avail|match_not_bol)); |
| 53 | VERIFY(!std::regex_match("\ra" + 1, re, match_prev_avail)); |
| 54 | VERIFY( std::regex_match("\ra" + 1, reml, match_prev_avail)); |
| 55 | VERIFY(!std::regex_match("xa" + 1, re, match_prev_avail)); |
| 56 | VERIFY(!std::regex_match("xa" + 1, reml, match_prev_avail)); |
| 57 | |
| 58 | std::regex bre("^a", basic|__multiline); |
| 59 | VERIFY(std::regex_match("\na" + 1, bre)); |
| 60 | VERIFY(!std::regex_match("\na" + 1, bre, match_not_bol)); |
| 61 | // multiline is ignored for any grammar except ECMAScript, |
| 62 | // so none of the following should match even though |
| 63 | // match_prev_avail is set and *--first == '\n'. |
| 64 | VERIFY(!std::regex_match("\na" + 1, bre, match_prev_avail)); |
| 65 | VERIFY(!std::regex_match("\na" + 1, bre, match_prev_avail|match_not_bol)); |
| 66 | VERIFY(!std::regex_match("\ra" + 1, bre, match_prev_avail)); |
| 67 | VERIFY(!std::regex_match("xa" + 1, bre, match_prev_avail)); |
| 68 | } |
| 69 | |
| 70 | int main() |
| 71 | { |
| 72 | test01(); |
| 73 | test_pr102480(); |
| 74 | } |