73 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: c++03, c++1110 11// Ensure that we don't allow iterators into temporary std::regex objects.12 13// <regex>14//15// class regex_iterator<BidirectionalIterator, charT, traits>16//17// regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,18// const regex_type&& re, int submatch = 0,19// regex_constants::match_flag_type m =20// regex_constants::match_default);21//22// template <size_t N>23// regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,24// const regex_type&& re,25// const int (&submatches)[N],26// regex_constants::match_flag_type m =27// regex_constants::match_default);28//29// regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,30// const regex_type&& re,31// initializer_list<int> submatches,32// regex_constants::match_flag_type m =33// regex_constants::match_default);34//35// template <std::size_t N>36// regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,37// const regex_type&& re,38// const std::vector<int>& submatches,39// regex_constants::match_flag_type m =40// regex_constants::match_default);41 42#include <iterator>43#include <regex>44#include <vector>45 46void f() {47 std::regex phone_numbers("\\d{3}-\\d{4}");48 const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";49 50 { // int submatch51 std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book) - 1, std::regex("\\d{3}-\\d{4}"), -1);52 // expected-error@-1 {{call to deleted constructor of 'std::cregex_token_iterator'}}53 }54 { // const int (&submatches)[N]55 const int indices[] = {-1, 0, 1};56 std::cregex_token_iterator i(57 std::begin(phone_book), std::end(phone_book) - 1, std::regex("\\d{3}-\\d{4}"), indices);58 // expected-error@-2 {{call to deleted constructor of 'std::cregex_token_iterator'}}59 }60 { // initializer_list<int> submatches61 std::cregex_token_iterator i(62 std::begin(phone_book), std::end(phone_book) - 1, std::regex("\\d{3}-\\d{4}"), {-1, 0, 1});63 // expected-error@-2 {{call to deleted constructor of 'std::cregex_token_iterator'}}64 }65 { // const std::vector<int>& submatches66 std::vector<int> v;67 v.push_back(-1);68 v.push_back(-1);69 std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book) - 1, std::regex("\\d{3}-\\d{4}"), v);70 // expected-error@-1 {{call to deleted constructor of 'std::cregex_token_iterator'}}71 }72}73