| 1 | // { dg-do run { target c++11 } } |
| 2 | // { dg-timeout-factor 2 } |
| 3 | #include <regex> |
| 4 | #include <string> |
| 5 | #include <testsuite_hooks.h> |
| 6 | |
| 7 | void test01() |
| 8 | { |
| 9 | const std::string s(1ul, '\0'); |
| 10 | std::regex re(s); |
| 11 | VERIFY( std::regex_match(s, re) ); // PR libstdc++/84110 |
| 12 | |
| 13 | #if __cpp_exceptions |
| 14 | using namespace std::regex_constants; |
| 15 | // See https://gcc.gnu.org/pipermail/gcc-patches/2021-October/582486.html |
| 16 | using std::regex_constants::extended; |
| 17 | |
| 18 | for (auto syn : {basic, extended, awk, grep, egrep}) |
| 19 | { |
| 20 | try |
| 21 | { |
| 22 | std::regex{s, syn}; // '\0' is not valid for other grammars |
| 23 | VERIFY( false ); |
| 24 | } |
| 25 | catch (const std::regex_error&) |
| 26 | { |
| 27 | } |
| 28 | } |
| 29 | #endif |
| 30 | } |
| 31 | |
| 32 | void test02() |
| 33 | { |
| 34 | const std::string s("uh-\0h", 5); |
| 35 | std::regex re(s); |
| 36 | VERIFY( std::regex_match(s, re) ); |
| 37 | } |
| 38 | |
| 39 | int main() |
| 40 | { |
| 41 | test01(); |
| 42 | test02(); |
| 43 | } |