Implement LWG Issues #2329 and #2332 - disallow iterators into temporary regexes and regexes into temporary strings

llvm-svn: 201717
This commit is contained in:
Marshall Clow 2014-02-19 21:21:11 +00:00
parent 0e4aa52e88
commit 7d35711187
9 changed files with 364 additions and 3 deletions

View File

@ -546,6 +546,13 @@ template <class ST, class SA, class Allocator, class charT, class traits>
const basic_regex<charT, traits>& e,
regex_constants::match_flag_type flags = regex_constants::match_default);
template <class ST, class SA, class Allocator, class charT, class traits>
bool
regex_match(const basic_string<charT, ST, SA>&& s,
match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
const basic_regex<charT, traits>& e,
regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14
template <class charT, class traits>
bool
regex_match(const charT* str, const basic_regex<charT, traits>& e,
@ -594,6 +601,13 @@ template <class ST, class SA, class Allocator, class charT, class traits>
const basic_regex<charT, traits>& e,
regex_constants::match_flag_type flags = regex_constants::match_default);
template <class ST, class SA, class Allocator, class charT, class traits>
bool
regex_search(const basic_string<charT, ST, SA>&& s,
match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
const basic_regex<charT, traits>& e,
regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14
template <class OutputIterator, class BidirectionalIterator,
class traits, class charT, class ST, class SA>
OutputIterator
@ -655,6 +669,10 @@ public:
regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
const regex_type& re,
regex_constants::match_flag_type m = regex_constants::match_default);
regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
const regex_type&& __re,
regex_constants::match_flag_type __m
= regex_constants::match_default) = delete; // C++14
regex_iterator(const regex_iterator&);
regex_iterator& operator=(const regex_iterator&);
@ -690,16 +708,29 @@ public:
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
const regex_type& re, int submatch = 0,
regex_constants::match_flag_type m = regex_constants::match_default);
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
const regex_type&& re, int submatch = 0,
regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
const regex_type& re, const vector<int>& submatches,
regex_constants::match_flag_type m = regex_constants::match_default);
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
const regex_type&& re, const vector<int>& submatches,
regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
const regex_type& re, initializer_list<int> submatches,
regex_constants::match_flag_type m = regex_constants::match_default);
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
const regex_type&& re, initializer_list<int> submatches,
regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
template <size_t N>
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
const regex_type& re, const int (&submatches)[N],
regex_constants::match_flag_type m = regex_constants::match_default);
template <size_t N>
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
const regex_type& re, const int (&submatches)[N],
regex_constants::match_flag_type m = regex_constants::match_default) = delete // C++14;
regex_token_iterator(const regex_token_iterator&);
regex_token_iterator& operator=(const regex_token_iterator&);
@ -5943,6 +5974,15 @@ regex_search(const basic_string<_CharT, _ST, _SA>& __s,
return __r;
}
#if _LIBCPP_STD_VER > 11
template <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
bool
regex_search(const basic_string<_Cp, _ST, _SA>&& __s,
match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
const basic_regex<_Cp, _Tp>& __e,
regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
#endif
// regex_match
template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
@ -5995,6 +6035,16 @@ regex_match(const basic_string<_CharT, _ST, _SA>& __s,
return _VSTD::regex_match(__s.begin(), __s.end(), __m, __e, __flags);
}
#if _LIBCPP_STD_VER > 11
template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
bool
regex_match(const basic_string<_CharT, _ST, _SA>&& __s,
match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
const basic_regex<_CharT, _Traits>& __e,
regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
#endif
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
bool
@ -6040,7 +6090,14 @@ public:
regex_iterator();
regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
const regex_type& __re,
regex_constants::match_flag_type __m = regex_constants::match_default);
regex_constants::match_flag_type __m
= regex_constants::match_default);
#if _LIBCPP_STD_VER > 11
regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
const regex_type&& __re,
regex_constants::match_flag_type __m
= regex_constants::match_default) = delete;
#endif
bool operator==(const regex_iterator& __x) const;
_LIBCPP_INLINE_VISIBILITY
@ -6156,16 +6213,38 @@ public:
const regex_type& __re, int __submatch = 0,
regex_constants::match_flag_type __m =
regex_constants::match_default);
#if _LIBCPP_STD_VER > 11
regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
const regex_type&& __re, int __submatch = 0,
regex_constants::match_flag_type __m =
regex_constants::match_default) = delete;
#endif
regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
const regex_type& __re, const vector<int>& __submatches,
regex_constants::match_flag_type __m =
regex_constants::match_default);
#if _LIBCPP_STD_VER > 11
regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
const regex_type&& __re, const vector<int>& __submatches,
regex_constants::match_flag_type __m =
regex_constants::match_default) = delete;
#endif
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
const regex_type& __re,
initializer_list<int> __submatches,
regex_constants::match_flag_type __m =
regex_constants::match_default);
#if _LIBCPP_STD_VER > 11
regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
const regex_type&& __re,
initializer_list<int> __submatches,
regex_constants::match_flag_type __m =
regex_constants::match_default) = delete;
#endif
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
template <size_t _Np>
regex_token_iterator(_BidirectionalIterator __a,
@ -6174,6 +6253,16 @@ public:
const int (&__submatches)[_Np],
regex_constants::match_flag_type __m =
regex_constants::match_default);
#if _LIBCPP_STD_VER > 11
template <std::size_t _Np>
regex_token_iterator(_BidirectionalIterator __a,
_BidirectionalIterator __b,
const regex_type&& __re,
const int (&__submatches)[_Np],
regex_constants::match_flag_type __m =
regex_constants::match_default) = delete;
#endif
regex_token_iterator(const regex_token_iterator&);
regex_token_iterator& operator=(const regex_token_iterator&);

View File

@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <regex>
// template <class ST, class SA, class Allocator, class charT, class traits>
// bool regex_match(const basic_string<charT, ST, SA>&&,
// match_results<
// typename basic_string<charT, ST, SA>::const_iterator,
// Allocator>&,
// const basic_regex<charT, traits>&,
// regex_constants::match_flag_type =
// regex_constants::match_default) = delete;
#include <__config>
#if _LIBCPP_STD_VER <= 11
#error
#else
#include <regex>
#include <cassert>
int main()
{
{
std::smatch m;
std::regex re{"*"};
std::regex_match(std::string("abcde"), m, re);
}
}
#endif

View File

@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <regex>
// template <class ST, class SA, class Allocator, class charT, class traits>
// bool regex_search(const basic_string<charT, ST, SA>&&,
// match_results<
// typename basic_string<charT, ST, SA>::const_iterator,
// Allocator>&,
// const basic_regex<charT, traits>&,
// regex_constants::match_flag_type =
// regex_constants::match_default) = delete;
#include <__config>
#if _LIBCPP_STD_VER <= 11
#error
#else
#include <regex>
#include <cassert>
int main()
{
{
std::smatch m;
std::regex re{"*"};
std::regex_search(std::string("abcde"), m, re);
}
}
#endif

View File

@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <regex>
// class regex_iterator<BidirectionalIterator, charT, traits>
// regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
// const regex_type&& re,
// int submatch = 0,
// regex_constants::match_flag_type m =
// regex_constants::match_default) = delete;
#include <__config>
#if _LIBCPP_STD_VER <= 11
#error
#else
#include <regex>
#include <cassert>
int main()
{
{
const char phone_book[] = "555-1234, 555-2345, 555-3456";
std::cregex_iterator i(
std::begin(phone_book), std::end(phone_book),
std::regex("\\d{3}-\\d{4}"));
}
}
#endif

View File

@ -0,0 +1,41 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <regex>
// class regex_iterator<BidirectionalIterator, charT, traits>
// template <size_t N>
// regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
// const regex_type&& re,
// const int (&submatches)[N],
// regex_constants::match_flag_type m =
// regex_constants::match_default);
#include <__config>
#if _LIBCPP_STD_VER <= 11
#error
#else
#include <regex>
#include <vector>
#include <cassert>
int main()
{
{
std::regex phone_numbers("\\d{3}-(\\d{4})");
const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
const int indices[] = {-1, 0, 1};
std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
std::regex("\\d{3}-\\d{4}"), indices);
}
}
#endif

View File

@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <regex>
// class regex_iterator<BidirectionalIterator, charT, traits>
// regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
// const regex_type&& re,
// initializer_list<int> submatches,
// regex_constants::match_flag_type m =
// regex_constants::match_default);
#include <__config>
#if _LIBCPP_STD_VER <= 11
#error
#else
#include <regex>
#include <cassert>
int main()
{
{
std::regex phone_numbers("\\d{3}-(\\d{4})");
const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
std::regex("\\d{3}-\\d{4}"), {-1, 0, 1});
}
}
#endif

View File

@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <regex>
// class regex_iterator<BidirectionalIterator, charT, traits>
// regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
// const regex_type&& re, int submatch = 0,
// regex_constants::match_flag_type m =
// regex_constants::match_default);
#include <__config>
#if _LIBCPP_STD_VER <= 11
#error
#else
#include <regex>
#include <cassert>
int main()
{
{
std::regex phone_numbers("\\d{3}-\\d{4}");
const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
std::regex("\\d{3}-\\d{4}"), -1);
}
}
#endif

View File

@ -0,0 +1,42 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <regex>
// class regex_iterator<BidirectionalIterator, charT, traits>
// template <std::size_t N>
// regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
// const regex_type&& re,
// const std::vector<int>& submatches,
// regex_constants::match_flag_type m =
// regex_constants::match_default);
#include <__config>
#if _LIBCPP_STD_VER <= 11
#error
#else
#include <regex>
#include <cassert>
int main()
{
{
std::regex phone_numbers("\\d{3}-(\\d{4})");
const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
std::vector<int> v;
v.push_back(-1);
v.push_back(-1);
std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
std::regex("\\d{3}-\\d{4}"), v);
}
}
#endif

View File

@ -253,9 +253,9 @@
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2322">2322</a></td><td>Associative(initializer_list, stuff) constructors are underspecified</td><td>Issaquah</td><td></td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2323">2323</a></td><td>vector::resize(n, t)'s specification should be simplified</td><td>Issaquah</td><td></td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2324">2324</a></td><td>Insert iterator constructors should use addressof()</td><td>Issaquah</td><td></td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2329">2329</a></td><td>regex_match()/regex_search() with match_results should forbid temporary strings</td><td>Issaquah</td><td></td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2329">2329</a></td><td>regex_match()/regex_search() with match_results should forbid temporary strings</td><td>Issaquah</td><td>Complete</td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2330">2330</a></td><td>regex("meow", regex::icase) is technically forbidden but should be permitted</td><td>Issaquah</td><td></td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2332">2332</a></td><td>regex_iterator/regex_token_iterator should forbid temporary regexes</td><td>Issaquah</td><td></td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2332">2332</a></td><td>regex_iterator/regex_token_iterator should forbid temporary regexes</td><td>Issaquah</td><td>Complete</td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2339">2339</a></td><td>Wording issue in nth_element</td><td>Issaquah</td><td></td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2341">2341</a></td><td>Inconsistency between basic_ostream::seekp(pos) and basic_ostream::seekp(off, dir)</td><td>Issaquah</td><td>Complete</td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2344">2344</a></td><td>quoted()'s interaction with padding is unclear</td><td>Issaquah</td><td></td></tr>