gcc/libstdc++-v3/include/bits
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
..
algorithmfwd.h
align.h libstdc++: Fix headers that can't be used as header units [PR 99413] 2021-03-10 15:27:41 +00:00
alloc_traits.h libstdc++: Fix std::allocator<void> for versioned namespace 2021-08-28 14:37:19 +01:00
allocated_ptr.h
allocator.h libstdc++: Fix std::allocator<void> for versioned namespace 2021-08-28 14:37:19 +01:00
atomic_base.h libstdc++: Implement std::atomic<T*>::compare_exchange_weak 2021-09-02 18:22:33 +01:00
atomic_futex.h
atomic_timed_wait.h libstdc++: Fix return values for atomic wait on futex 2021-09-28 21:27:04 +01:00
atomic_wait.h libstdc++: Define macro before it is first checked 2021-09-28 20:30:59 +01:00
basic_ios.h libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
basic_ios.tcc libstdc++: Implement LWG 581 for std:ostream::flush() 2021-06-25 18:47:39 +01:00
basic_string.h libstdc++: Add noexcept to std::to_string overloads that don't allocate 2021-09-16 22:59:47 +01:00
basic_string.tcc libstdc++: Move COW string definitions to separate header 2021-07-27 12:04:18 +01:00
boost_concept_check.h libstdc++: Fix concept checks for iterators 2021-09-28 20:22:51 +01:00
c++0x_warning.h
c++config libstdc++: Deprecate std::random_shuffle for C++14 2021-08-03 15:30:35 +01:00
char_traits.h libstdc++: Simplify constexpr checks in std::char_traits [PR 91488] 2021-06-17 22:00:58 +01:00
charconv.h
codecvt.h libstdc++: Fix headers that can't be used as header units [PR 99413] 2021-03-10 15:27:41 +00:00
concept_check.h
cow_string.h libstdc++: Only define basic_string::contains for C++23 2021-08-17 14:22:50 +01:00
cpp_type_traits.h libstdc++: Use __extension__ instead of diagnostic pragmas 2021-07-16 15:03:03 +01:00
deque.tcc libstdc++: Use std::addressof to avoid ADL for operator& [PR 60497] 2021-04-30 14:57:40 +01:00
enable_special_members.h libstdc++: Fix headers that can't be used as header units [PR 99413] 2021-03-10 15:27:41 +00:00
erase_if.h libstdc++: Fix headers that can't be used as header units [PR 99413] 2021-03-10 15:27:41 +00:00
forward_list.h libstdc++: Add [[nodiscard]] to sequence containers 2021-08-04 12:54:29 +01:00
forward_list.tcc
fs_dir.h libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
fs_fwd.h libstdc++: Improvements to Doxygen markup 2021-07-01 18:45:48 +01:00
fs_ops.h libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
fs_path.h libstdc++: Fix mismatched noexcept-specifiers in filesystem::path [PR102499] 2021-09-28 17:30:05 +01:00
fstream.tcc
functexcept.h
functional_hash.h libstdc++: Use __extension__ instead of diagnostic pragmas 2021-07-16 15:03:03 +01:00
gslice_array.h libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
gslice.h libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
hashtable_policy.h libstdc++: Value-initialize objects held by EBO helpers [PR 100863] 2021-06-02 13:33:41 +01:00
hashtable.h libstdc++: Fix non-default constructors for hash containers [PR101583] 2021-07-22 19:39:58 +01:00
indirect_array.h libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
invoke.h libstdc++: Fix headers that can't be used as header units [PR 99413] 2021-03-10 15:27:41 +00:00
ios_base.h
istream.tcc libstdc++: Implement LWG 415 for std::ws 2021-06-28 13:34:49 +01:00
iterator_concepts.h libstdc++: Add [[nodiscard]] to iterators and related utilities 2021-08-04 12:54:28 +01:00
list.tcc
locale_classes.h libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
locale_classes.tcc
locale_conv.h libstdc++: Avoid using std::unique_ptr in <locale> 2021-08-03 15:06:56 +01:00
locale_facets_nonio.h libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
locale_facets_nonio.tcc
locale_facets.h libstdc++: diagnose some misuses of [locale.convenience] functions [PR 89728] 2021-05-17 17:58:14 +01:00
locale_facets.tcc
localefwd.h
mask_array.h libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
max_size_type.h libstdc++: Simplify numeric_limits<__max_size_type> 2021-07-16 15:03:03 +01:00
memoryfwd.h libstdc++: Fix missing members in std::allocator<void> 2021-05-11 16:11:01 +01:00
move.h libstdc++: Improve std::forward static assert message 2021-09-28 17:30:05 +01:00
node_handle.h
ostream_insert.h libstdc++: Fix headers that can't be used as header units [PR 99413] 2021-03-10 15:27:41 +00:00
ostream.tcc libstdc++: Avoid intercepting exception in ostream::write 2021-06-25 18:47:44 +01:00
parse_numbers.h libstdc++: Fix headers that can't be used as header units [PR 99413] 2021-03-10 15:27:41 +00:00
postypes.h libstdc++: Remove GLIBCXX_CHECK_INT64_T checks 2021-04-30 20:30:46 +01:00
predefined_ops.h libstdc++: Fix headers that can't be used as header units [PR 99413] 2021-03-10 15:27:41 +00:00
ptr_traits.h
quoted_string.h
random.h libstdc++: Modernize <bits/random.h> helpers 2021-07-16 15:03:03 +01:00
random.tcc libstdc++: Optimize std::seed_seq construction 2021-08-17 16:53:19 +01:00
range_access.h libstdc++: Remove redundant 'inline' specifiers 2021-09-24 15:38:44 +01:00
ranges_algo.h libstdc++: Add missing std::move to ranges::copy/move/reverse_copy [PR101599] 2021-08-02 15:30:15 -04:00
ranges_algobase.h libstdc++: Add missing std::move to ranges::copy/move/reverse_copy [PR101599] 2021-08-02 15:30:15 -04:00
ranges_base.h libstdc++: Move [[nodiscard]] attributes again [PR101782] 2021-08-05 19:01:51 +01:00
ranges_cmp.h libstdc++: Sync __cpp_lib_ranges macro defined in ranges_cmp.h 2021-06-21 09:45:31 -04:00
ranges_uninitialized.h libstdc++: Use std::addressof in ranges::uninitialized_xxx [PR101571] 2021-07-22 14:37:24 +01:00
ranges_util.h libstdc++: Rename __detail::__not_same_as helper 2021-08-17 14:22:49 +01:00
refwrap.h libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
regex_automaton.h libstdc++: Remove obfuscating typedefs in <regex> 2021-09-28 20:38:58 +01:00
regex_automaton.tcc libstdc++: Reduce use of debug containers in <regex> 2021-08-09 20:46:56 +01:00
regex_compiler.h libstdc++: Simplify std::basic_regex construction and assignment 2021-09-29 13:48:02 +01:00
regex_compiler.tcc libstdc++: Remove obfuscating typedefs in <regex> 2021-09-28 20:38:58 +01:00
regex_constants.h libstdc++: Fix more doxygen markup for group close commands 2021-04-08 21:42:58 +01:00
regex_error.h libstdc++: Add noexcept to functions in <regex> 2021-09-28 20:38:57 +01:00
regex_executor.h libstdc++: Reduce use of debug containers in <regex> 2021-08-09 20:46:56 +01:00
regex_executor.tcc libstdc++: Tweaks to <regex> to avoid warnings 2021-09-28 20:38:58 +01:00
regex_scanner.h libstdc++: Remove obfuscating typedefs in <regex> 2021-09-28 20:38:58 +01:00
regex_scanner.tcc libstdc++: Remove obfuscating typedefs in <regex> 2021-09-28 20:38:58 +01:00
regex.h libstdc++: Simplify std::basic_regex construction and assignment 2021-09-29 13:48:02 +01:00
regex.tcc libstdc++: Reduce use of debug containers in <regex> 2021-08-09 20:46:56 +01:00
semaphore_base.h libstdc++: Fix for deadlock in std::counting_semaphore [PR100806] 2021-06-22 11:06:07 -07:00
shared_ptr_atomic.h libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
shared_ptr_base.h libstdc++: Implement LWG 2762 for std::unique_ptr::operator* 2021-06-24 14:04:02 +01:00
shared_ptr.h libstdc++: Improve doxygen docs for smart pointers 2021-08-19 13:02:12 +01:00
slice_array.h libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
specfun.h libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
sstream.tcc
std_abs.h libstdc++: Use __extension__ instead of diagnostic pragmas 2021-07-16 15:03:03 +01:00
std_function.h libstdc++: Name std::function template parameter 2021-08-28 11:52:22 +01:00
std_mutex.h libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
std_thread.h libstdc++: Add missing noexcept on std::thread member function [PR 100298] 2021-04-28 12:45:49 +01:00
stl_algo.h libstdc++: Enable doxygen processing for C++20 components 2021-08-18 15:02:31 +01:00
stl_algobase.h libstdc++: Fix _OutputIteratorConcept checks in algorithms 2021-09-28 20:22:50 +01:00
stl_bvector.h libstdc++: Add [[nodiscard]] to sequence containers 2021-08-04 12:54:29 +01:00
stl_construct.h
stl_deque.h libstdc++: Add [[nodiscard]] to sequence containers 2021-08-04 12:54:29 +01:00
stl_function.h libstdc++: Improve doxygen comments in <bits/stl_function.h> 2021-08-18 15:07:16 +01:00
stl_heap.h
stl_iterator_base_funcs.h libstdc++: Add [[nodiscard]] to iterators and related utilities 2021-08-04 12:54:28 +01:00
stl_iterator_base_types.h libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
stl_iterator.h libstdc++: Specialize std::pointer_traits<__normal_iterator<I,C>> 2021-09-28 20:22:50 +01:00
stl_list.h libstdc++: Add [[nodiscard]] to sequence containers 2021-08-04 12:54:29 +01:00
stl_map.h libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
stl_multimap.h libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
stl_multiset.h libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
stl_numeric.h libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
stl_pair.h libstdc++: Reduce header dependencies on <array> and <utility> 2021-07-27 12:04:18 +01:00
stl_queue.h libstdc++: Move [[nodiscard]] attributes again [PR101782] 2021-08-05 19:01:51 +01:00
stl_raw_storage_iter.h
stl_relops.h libstdc++: Update documentation comments for namespace rel_ops 2021-07-23 11:22:10 +01:00
stl_set.h libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
stl_stack.h libstdc++: Add [[nodiscard]] to sequence containers 2021-08-04 12:54:29 +01:00
stl_tempbuf.h
stl_tree.h libstdc++: Tweak whitespace 2021-08-19 13:02:11 +01:00
stl_uninitialized.h libstdc++: Fix comment typo 2021-08-28 11:52:22 +01:00
stl_vector.h libstdc++: Add [[nodiscard]] to sequence containers 2021-08-04 12:54:29 +01:00
stream_iterator.h libstdc++: Add [[nodiscard]] to iterators and related utilities 2021-08-04 12:54:28 +01:00
streambuf_iterator.h libstdc++: Add [[nodiscard]] to iterators and related utilities 2021-08-04 12:54:28 +01:00
streambuf.tcc libstdc++: Remove redundant explicit instantiations 2021-06-28 15:16:08 +01:00
string_view.tcc
stringfwd.h
this_thread_sleep.h libstdc++: Improve Doxygen documentation groups [PR 101258] 2021-07-01 00:25:46 +01:00
uniform_int_dist.h libstdc++: Use __extension__ instead of diagnostic pragmas 2021-07-16 15:03:03 +01:00
unique_lock.h libstdc++: Fix headers that can't be used as header units [PR 99413] 2021-03-10 15:27:41 +00:00
unique_ptr.h libstdc++: Add noexcept to unique_ptr accessors 2021-09-16 22:59:46 +01:00
unordered_map.h libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
unordered_set.h libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
uses_allocator_args.h libstdc++: Fix even more doxygen markup for group close commands 2021-04-09 13:09:23 +01:00
uses_allocator.h
utility.h libstdc++: Reduce header dependencies on <array> and <utility> 2021-07-27 12:04:18 +01:00
valarray_after.h
valarray_array.h
valarray_array.tcc
valarray_before.h
vector.tcc libstdc++: Use std::addressof to avoid ADL for operator& [PR 60497] 2021-04-30 14:57:40 +01:00