gcc/libstdc++-v3/testsuite
Jonathan Wakely b59be1adba libstdc++: Simplify std::basic_regex construction and assignment
Introduce a new _M_compile function which does the common work needed by
all constructors and assignment. Call that directly to avoid multiple
levels of constructor delegation or calls to basic_regex::assign
overloads.

For assignment, there is no need to construct a std::basic_string if we
already have a contiguous sequence of the correct character type, and no
need to construct a temporary basic_regex when assigning from an
existing basic_regex.

Also define the copy and move assignment operators as defaulted, which
does the right thing without constructing a temporary and swapping it.
Copying or moving the shared_ptr member cannot fail, so they can be
noexcept. The assign(const basic_regex&) and assign(basic_regex&&)
member can then be defined in terms of copy or move assignment.

The new _M_compile function takes pointer arguments, so the caller has
to convert arbitrary iterator ranges into a contiguous sequence of
characters. With that simplification, the __compile_nfa helpers are not
needed and can be removed.

This also fixes a bug where construction from a contiguous sequence with
the wrong character type would fail to compile, rather than converting
the elements to the regex character type.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>

libstdc++-v3/ChangeLog:

	* include/bits/regex.h (__detail::__is_contiguous_iter): Move
	here from <bits/regex_compiler.h>.
	(basic_regex::_M_compile): New function to compile an NFA from
	a regular expression string.
	(basic_regex::basic_regex): Use _M_compile instead of delegating
	to other constructors.
	(basic_regex::operator=(const basic_regex&)): Define as
	defaulted.
	(basic_regex::operator=(initializer_list<C>)): Use _M_compile.
	(basic_regex::assign(const basic_regex&)): Use copy assignment.
	(basic_regex::assign(basic_regex&&)): Use move assignment.
	(basic_regex::assign(const C*, flag_type)): Use _M_compile
	instead of constructing a temporary string.
	(basic_regex::assign(const C*, size_t, flag_type)): Likewise.
	(basic_regex::assign(const basic_string<C,T,A>&, flag_type)):
	Use _M_compile instead of constructing a temporary basic_regex.
	(basic_regex::assign(InputIter, InputIter, flag_type)): Avoid
	constructing a temporary string for contiguous iterators of the
	right value type.
	* include/bits/regex_compiler.h (__is_contiguous_iter): Move to
	<bits/regex.h>.
	(__enable_if_contiguous_iter, __disable_if_contiguous_iter)
	(__compile_nfa): Remove.
	* testsuite/28_regex/basic_regex/assign/exception_safety.cc: New
	test.
	* testsuite/28_regex/basic_regex/ctors/char/other.cc: New test.
2021-09-29 13:48:02 +01:00
..
17_intro libstdc++: Fix 17_intro/names.cc failures on Solaris 2021-08-31 14:17:53 +01:00
18_support libstdc++: Add [[nodiscard]] to <compare> 2021-08-05 15:16:58 +01:00
19_diagnostics libstdc++: Disable PCH for test that depends on a macro being defined 2021-09-23 16:07:39 +01:00
20_util libstdc++: Fix 48631_neg test in _GLIBCXX_INLINE_VERSION mode 2021-09-28 22:09:48 +02:00
21_strings libstdc++: Add [[nodiscard]] to iterators and related utilities 2021-08-04 12:54:28 +01:00
22_locale libstdc++: Fix new test for C++98 mode [PR 89728] 2021-06-01 19:02:42 +01:00
23_containers libstdc++: Skip container adaptor tests that fail concept checks 2021-09-28 20:22:51 +01:00
24_iterators libstdc++: Fix concept checks for iterators 2021-09-28 20:22:51 +01:00
25_algorithms libstdc++: Improve types used as iterators in testsuite 2021-09-28 20:22:51 +01:00
26_numerics libstdc++: Rename tests with incorrect extension 2021-09-17 12:40:41 +01:00
27_io libstdc++: Rename tests with incorrect extension 2021-09-17 12:40:41 +01:00
28_regex libstdc++: Simplify std::basic_regex construction and assignment 2021-09-29 13:48:02 +01:00
29_atomics libstdc++: Fix UB in atomic_ref/wait_notify.cc [PR101761] 2021-09-16 14:48:17 -07:00
30_threads c++: limit instantiation with ill-formed class [PR96286] 2021-08-30 17:25:21 -04:00
abi Update copyright years. 2021-01-04 10:26:59 +01:00
backward Update copyright years. 2021-01-04 10:26:59 +01:00
config Update copyright years. 2021-01-04 10:26:59 +01:00
data
decimal Update copyright years. 2021-01-04 10:26:59 +01:00
experimental libstdc++: Use "test.invalid." for invalid hostname 2021-09-10 15:10:21 +01:00
ext libstdc++: Increase timeout factor for slow pb_ds tests 2021-09-16 23:06:38 +01:00
lib libstdc++: Avoid illegal argument to verbose in dg-test callback, continued 2021-08-17 21:05:27 +02:00
libstdc++-abi Update copyright years. 2021-01-04 10:26:59 +01:00
libstdc++-dg libstdc++: Add std::experimental::simd from the Parallelism TS 2 2021-01-27 16:37:26 +00:00
libstdc++-prettyprinters libstdc++: Fix vector<bool> printer tests to work in debug mode 2021-08-18 14:26:38 +01:00
libstdc++-xmethods Update copyright years. 2021-01-04 10:26:59 +01:00
performance Update copyright years. 2021-01-04 10:26:59 +01:00
special_functions Update copyright years. 2021-01-04 10:26:59 +01:00
std libstdc++: Add default template argument to basic_istream_view 2021-08-23 16:17:10 +01:00
tr1 libstdc++: Fix some tests that fail in C++20 mode 2021-04-12 12:30:07 +01:00
tr2 Update copyright years. 2021-01-04 10:26:59 +01:00
util libstdc++: Fix last std::tuple constructor missing 'constexpr' [PR102270] 2021-09-17 20:43:34 +01:00
Makefile.am libstdc++: Remove -fno-tree-vrp after PR98834 was resolved 2021-06-23 18:28:59 +01:00
Makefile.in libstdc++: Remove -fno-tree-vrp after PR98834 was resolved 2021-06-23 18:28:59 +01:00