diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2014-02-19 21:21:11 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2014-02-19 21:21:11 +0000 |
commit | 7d357111876c1731ba794092662c48d88eda0004 (patch) | |
tree | 574a8edf7621d5845c62140fbbf9c77f567ebf53 | |
parent | 0e4aa52e883cf91edef9df73575260f2ffb8b978 (diff) | |
download | bcm5719-llvm-7d357111876c1731ba794092662c48d88eda0004.tar.gz bcm5719-llvm-7d357111876c1731ba794092662c48d88eda0004.zip |
Implement LWG Issues #2329 and #2332 - disallow iterators into temporary regexes and regexes into temporary strings
llvm-svn: 201717
9 files changed, 364 insertions, 3 deletions
diff --git a/libcxx/include/regex b/libcxx/include/regex index 8c95145fe0b..e121738a9b5 100644 --- a/libcxx/include/regex +++ b/libcxx/include/regex @@ -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&); @@ -691,15 +709,28 @@ public: 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&); diff --git a/libcxx/test/re/re.alg/re.alg.match/basic.fail.cpp b/libcxx/test/re/re.alg/re.alg.match/basic.fail.cpp new file mode 100644 index 00000000000..d3b922c0782 --- /dev/null +++ b/libcxx/test/re/re.alg/re.alg.match/basic.fail.cpp @@ -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 diff --git a/libcxx/test/re/re.alg/re.alg.search/basic.fail.cpp b/libcxx/test/re/re.alg/re.alg.search/basic.fail.cpp new file mode 100644 index 00000000000..692ee94d944 --- /dev/null +++ b/libcxx/test/re/re.alg/re.alg.search/basic.fail.cpp @@ -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 diff --git a/libcxx/test/re/re.iter/re.regiter/re.regiter.cnstr/cnstr.fail.cpp b/libcxx/test/re/re.iter/re.regiter/re.regiter.cnstr/cnstr.fail.cpp new file mode 100644 index 00000000000..9c17287cdb8 --- /dev/null +++ b/libcxx/test/re/re.iter/re.regiter/re.regiter.cnstr/cnstr.fail.cpp @@ -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 diff --git a/libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/array.fail.cpp b/libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/array.fail.cpp new file mode 100644 index 00000000000..ed3c9feaa34 --- /dev/null +++ b/libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/array.fail.cpp @@ -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 diff --git a/libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/init.fail.cpp b/libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/init.fail.cpp new file mode 100644 index 00000000000..13120f36e40 --- /dev/null +++ b/libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/init.fail.cpp @@ -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 diff --git a/libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/int.fail.cpp b/libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/int.fail.cpp new file mode 100644 index 00000000000..dba11c27536 --- /dev/null +++ b/libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/int.fail.cpp @@ -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 diff --git a/libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/vector.fail.cpp b/libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/vector.fail.cpp new file mode 100644 index 00000000000..fd75a8b6854 --- /dev/null +++ b/libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/vector.fail.cpp @@ -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 diff --git a/libcxx/www/cxx1y_status.html b/libcxx/www/cxx1y_status.html index 1d57c1bc41d..bb99d19f31c 100644 --- a/libcxx/www/cxx1y_status.html +++ b/libcxx/www/cxx1y_status.html @@ -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> |