40 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: no-exceptions10// <regex>11 12// template <class charT, class traits = regex_traits<charT>> class basic_regex;13 14// template <class ST, class SA>15// basic_regex(const basic_string<charT, ST, SA>& s);16 17#include <regex>18#include <cassert>19#include "test_macros.h"20 21static bool error_range_thrown(const char *pat)22{23 bool result = false;24 try {25 std::regex re(pat);26 } catch (const std::regex_error &ex) {27 result = (ex.code() == std::regex_constants::error_range);28 }29 return result;30}31 32int main(int, char**)33{34 assert(error_range_thrown("([\\w-a])"));35 assert(error_range_thrown("([a-\\w])"));36 assert(error_range_thrown("([w-a])"));37 38 return 0;39}40