Home | History | Annotate | Download | only in re.regex.construct
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // UNSUPPORTED: libcpp-no-exceptions
     11 // <regex>
     12 
     13 // template <class charT, class traits = regex_traits<charT>> class basic_regex;
     14 
     15 // template <class ST, class SA>
     16 //    basic_regex(const basic_string<charT, ST, SA>& s);
     17 
     18 #include <regex>
     19 #include <cassert>
     20 #include "test_macros.h"
     21 
     22 static bool error_badrepeat_thrown(const char *pat)
     23 {
     24     bool result = false;
     25     try {
     26         std::regex re(pat);
     27     } catch (const std::regex_error &ex) {
     28         result = (ex.code() == std::regex_constants::error_badrepeat);
     29     }
     30     return result;
     31 }
     32 
     33 int main()
     34 {
     35     assert(error_badrepeat_thrown("?a"));
     36     assert(error_badrepeat_thrown("*a"));
     37     assert(error_badrepeat_thrown("+a"));
     38     assert(error_badrepeat_thrown("{a"));
     39 
     40     assert(error_badrepeat_thrown("?(a+)"));
     41     assert(error_badrepeat_thrown("*(a+)"));
     42     assert(error_badrepeat_thrown("+(a+)"));
     43     assert(error_badrepeat_thrown("{(a+)"));
     44 }
     45