From 7d357111876c1731ba794092662c48d88eda0004 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Wed, 19 Feb 2014 21:21:11 +0000 Subject: [PATCH] Implement LWG Issues #2329 and #2332 - disallow iterators into temporary regexes and regexes into temporary strings llvm-svn: 201717 --- libcxx/include/regex | 91 ++++++++++++++++++- .../re/re.alg/re.alg.match/basic.fail.cpp | 38 ++++++++ .../re/re.alg/re.alg.search/basic.fail.cpp | 38 ++++++++ .../re.regiter.cnstr/cnstr.fail.cpp | 38 ++++++++ .../re.tokiter.cnstr/array.fail.cpp | 41 +++++++++ .../re.tokiter/re.tokiter.cnstr/init.fail.cpp | 38 ++++++++ .../re.tokiter/re.tokiter.cnstr/int.fail.cpp | 37 ++++++++ .../re.tokiter.cnstr/vector.fail.cpp | 42 +++++++++ libcxx/www/cxx1y_status.html | 4 +- 9 files changed, 364 insertions(+), 3 deletions(-) create mode 100644 libcxx/test/re/re.alg/re.alg.match/basic.fail.cpp create mode 100644 libcxx/test/re/re.alg/re.alg.search/basic.fail.cpp create mode 100644 libcxx/test/re/re.iter/re.regiter/re.regiter.cnstr/cnstr.fail.cpp create mode 100644 libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/array.fail.cpp create mode 100644 libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/init.fail.cpp create mode 100644 libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/int.fail.cpp create mode 100644 libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/vector.fail.cpp diff --git a/libcxx/include/regex b/libcxx/include/regex index 8c95145fe0bd..e121738a9b5a 100644 --- a/libcxx/include/regex +++ b/libcxx/include/regex @@ -546,6 +546,13 @@ template const basic_regex& e, regex_constants::match_flag_type flags = regex_constants::match_default); +template + bool + regex_match(const basic_string&& s, + match_results::const_iterator, Allocator>& m, + const basic_regex& e, + regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14 + template bool regex_match(const charT* str, const basic_regex& e, @@ -594,6 +601,13 @@ template const basic_regex& e, regex_constants::match_flag_type flags = regex_constants::match_default); +template + bool + regex_search(const basic_string&& s, + match_results::const_iterator, Allocator>& m, + const basic_regex& e, + regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14 + template 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& submatches, regex_constants::match_flag_type m = regex_constants::match_default); + regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, + const regex_type&& re, const vector& 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 submatches, regex_constants::match_flag_type m = regex_constants::match_default); + regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, + const regex_type&& re, initializer_list submatches, + regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14 template 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 + 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 +bool +regex_search(const basic_string<_Cp, _ST, _SA>&& __s, + match_results::const_iterator, _Ap>&, + const basic_regex<_Cp, _Tp>& __e, + regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; +#endif + // regex_match template @@ -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 +inline _LIBCPP_INLINE_VISIBILITY +bool +regex_match(const basic_string<_CharT, _ST, _SA>&& __s, + match_results::const_iterator, _Allocator>& __m, + const basic_regex<_CharT, _Traits>& __e, + regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; +#endif + template 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& __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& __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 __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 __submatches, + regex_constants::match_flag_type __m = + regex_constants::match_default) = delete; +#endif #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS template 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 + 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 000000000000..d3b922c0782c --- /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. +// +//===----------------------------------------------------------------------===// + +// + +// template +// bool regex_match(const basic_string&&, +// match_results< +// typename basic_string::const_iterator, +// Allocator>&, +// const basic_regex&, +// regex_constants::match_flag_type = +// regex_constants::match_default) = delete; + +#include <__config> + +#if _LIBCPP_STD_VER <= 11 +#error +#else + +#include +#include + +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 000000000000..692ee94d9441 --- /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. +// +//===----------------------------------------------------------------------===// + +// + +// template +// bool regex_search(const basic_string&&, +// match_results< +// typename basic_string::const_iterator, +// Allocator>&, +// const basic_regex&, +// regex_constants::match_flag_type = +// regex_constants::match_default) = delete; + +#include <__config> + +#if _LIBCPP_STD_VER <= 11 +#error +#else + +#include +#include + +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 000000000000..9c17287cdb8a --- /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. +// +//===----------------------------------------------------------------------===// + +// + +// class regex_iterator + +// 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 +#include + +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 000000000000..ed3c9feaa342 --- /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. +// +//===----------------------------------------------------------------------===// + +// + +// class regex_iterator + +// template +// 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 +#include +#include + +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 000000000000..13120f36e405 --- /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. +// +//===----------------------------------------------------------------------===// + +// + +// class regex_iterator + +// regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, +// const regex_type&& re, +// initializer_list submatches, +// regex_constants::match_flag_type m = +// regex_constants::match_default); + +#include <__config> + +#if _LIBCPP_STD_VER <= 11 +#error +#else + +#include +#include + +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 000000000000..dba11c27536c --- /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. +// +//===----------------------------------------------------------------------===// + +// + +// class regex_iterator + +// 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 +#include + +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 000000000000..fd75a8b68544 --- /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. +// +//===----------------------------------------------------------------------===// + +// + +// class regex_iterator + +// template +// regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, +// const regex_type&& re, +// const std::vector& submatches, +// regex_constants::match_flag_type m = +// regex_constants::match_default); + +#include <__config> + +#if _LIBCPP_STD_VER <= 11 +#error +#else + +#include +#include + +int main() +{ + { + std::regex phone_numbers("\\d{3}-(\\d{4})"); + const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end"; + std::vector 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 1d57c1bc41d2..bb99d19f31c2 100644 --- a/libcxx/www/cxx1y_status.html +++ b/libcxx/www/cxx1y_status.html @@ -253,9 +253,9 @@ 2322Associative(initializer_list, stuff) constructors are underspecifiedIssaquah 2323vector::resize(n, t)'s specification should be simplifiedIssaquah 2324Insert iterator constructors should use addressof()Issaquah - 2329regex_match()/regex_search() with match_results should forbid temporary stringsIssaquah + 2329regex_match()/regex_search() with match_results should forbid temporary stringsIssaquahComplete 2330regex("meow", regex::icase) is technically forbidden but should be permittedIssaquah - 2332regex_iterator/regex_token_iterator should forbid temporary regexesIssaquah + 2332regex_iterator/regex_token_iterator should forbid temporary regexesIssaquahComplete 2339Wording issue in nth_elementIssaquah 2341Inconsistency between basic_ostream::seekp(pos) and basic_ostream::seekp(off, dir)IssaquahComplete 2344quoted()'s interaction with padding is unclearIssaquah