xref: /llvm-project/libcxx/test/std/re/re.regex/re.regex.construct/bad_repeat.pass.cpp (revision 8c61114c53dcd6139a4a750925b91ed9bcf4178c)
1983d1781SMarshall Clow //===----------------------------------------------------------------------===//
2983d1781SMarshall Clow //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6983d1781SMarshall Clow //
7983d1781SMarshall Clow //===----------------------------------------------------------------------===//
8983d1781SMarshall Clow 
9*8c61114cSLouis Dionne // UNSUPPORTED: no-exceptions
10983d1781SMarshall Clow // <regex>
11983d1781SMarshall Clow 
12983d1781SMarshall Clow // template <class charT, class traits = regex_traits<charT>> class basic_regex;
13983d1781SMarshall Clow 
14983d1781SMarshall Clow // template <class ST, class SA>
15983d1781SMarshall Clow //    basic_regex(const basic_string<charT, ST, SA>& s);
16983d1781SMarshall Clow 
17983d1781SMarshall Clow #include <regex>
18983d1781SMarshall Clow #include <cassert>
19fd5ceb22SMarshall Clow #include "test_macros.h"
20983d1781SMarshall Clow 
error_badrepeat_thrown(const char * pat)21983d1781SMarshall Clow static bool error_badrepeat_thrown(const char *pat)
22983d1781SMarshall Clow {
23983d1781SMarshall Clow     bool result = false;
24983d1781SMarshall Clow     try {
25983d1781SMarshall Clow         std::regex re(pat);
26983d1781SMarshall Clow     } catch (const std::regex_error &ex) {
27983d1781SMarshall Clow         result = (ex.code() == std::regex_constants::error_badrepeat);
28983d1781SMarshall Clow     }
29983d1781SMarshall Clow     return result;
30983d1781SMarshall Clow }
31983d1781SMarshall Clow 
main(int,char **)322df59c50SJF Bastien int main(int, char**)
33983d1781SMarshall Clow {
34983d1781SMarshall Clow     assert(error_badrepeat_thrown("?a"));
35983d1781SMarshall Clow     assert(error_badrepeat_thrown("*a"));
36983d1781SMarshall Clow     assert(error_badrepeat_thrown("+a"));
37983d1781SMarshall Clow     assert(error_badrepeat_thrown("{a"));
38983d1781SMarshall Clow 
39983d1781SMarshall Clow     assert(error_badrepeat_thrown("?(a+)"));
40983d1781SMarshall Clow     assert(error_badrepeat_thrown("*(a+)"));
41983d1781SMarshall Clow     assert(error_badrepeat_thrown("+(a+)"));
42983d1781SMarshall Clow     assert(error_badrepeat_thrown("{(a+)"));
432df59c50SJF Bastien 
442df59c50SJF Bastien   return 0;
45983d1781SMarshall Clow }
46