mirror of
https://gcc.gnu.org/git/gcc.git
synced 2026-02-22 12:00:03 -05:00
master
9456 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
918cf3a50d |
libstdc++: Rework constant_wrapper assignments and increments
This implements LWG4383 with LWG4500, LWG4523 follow-up corrections. This patch changes the constant_wrapper assignments operator (including compounds), increment and decrement to apply directly to value. In consequence the operators are only supported for types, for which above operations can be applied on const value. libstdc++-v3/ChangeLog: * include/std/type_traits (_CWOperators::operator++) (_CWOperators::operator--, _CWOperators::operator+=) (_CWOperators::operator-=, _CWOperators::operator*=) (_CWOperators::operator/=, _CWOperators::operator%=) (_CWOperators::operator&=, _CWOperators::operator|=) (_CWOperators::operator^=, _CWOperators::operator<<=) (_CWOperators::operator>>=, constant_wrapper::operator=): Adjust definitions to apply operator on value. * testsuite/20_util/constant_wrapper/generic.cc: Remove test_pseudo_mutator. * testsuite/20_util/constant_wrapper/instantiate.cc: Test that operators are not provided if wrapped type do not support them, or provide mutable operators. |
||
|
|
8ba1e2077f |
libstdc++: Add [[no_unique_address]] to repeat_view::_M_value [PR121402]
PR libstdc++/121402 libstdc++-v3/ChangeLog: * include/std/ranges (repeat_view::_M_value): Add [[no_unique_address]]. * testsuite/std/ranges/adaptors/sizeof.cc [__cpp_lib_ranges_repeat]: New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> |
||
|
|
716ec14c57 |
libstdc++: Implement rvalue overload for basic_string::substr() [PR119745]
This paper implement the changes from P2438R2 basic_string::substr() && paper into C++26. The additional substr and constructor overload are implemented only for SSO string, as they require mutating the content (if reused), and thus would require copy of the string anyway for COW strings. (In consequence allocators implicitly constructible from int remain ambiguous for C++11 ABI strings, see r16-7497-gfa1149534d8580). In addition to cases when the allocators are not compatible (equal), this patch does not reuse (transfer) allocator storage, if the selected substring fits inside the SSO buffer, so we do not risk keeping large chunk of memory for few characters. (This also covers cases when the source stored the content in the local buffer). As this additional overloads are meant to be optimization, in contrast to move constructor, the source is left unmodified if the allocation is not transferred. This avoid introducing a write (of null terminator) to previously untouched, heap allocated, memory. Separate overloads for substr(size_type __pos, size_type __n) and substr(size_type __pos == 0), that delegate to corresponding constructor, are provided to avoid the check of __n against the length() in the later case. Finally, the signatures of existing substr() overload are not modified (no longer required since C++20), which avoid any impact on the ABI. PR libstdc++/119745 libstdc++-v3/ChangeLog: * include/bits/basic_string.h (basic_string::_M_construct) [__cplusplus >= 202302L]: Declare. (basic_string::basic_string(basic_string&&, size_type, const _Alloc&)) (basic_string(basic_string&&, size_type, size_type, const _Alloc&)) (basic_string::substr(size_type, size_type) &&) (basic_string::substr(size_type) &&) [__cplusplus >= 202302L]: Define. * include/bits/basic_string.tcc (basic_string::_M_construct) [__cplusplus >= 202302L]: Define. * testsuite/21_strings/basic_string/operations/substr/rvalue.cc: New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Reviewed-by: Patrick Palka <ppalka@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com> |
||
|
|
55b87e1b3a |
libstdc++: Rename std::submdspan_extents and std::submdspan_canonicalize_slices
This patch implements LWG 4491, addressing C++26 NB comments. libstdc++-v3/ChangeLog: * include/std/mdspan (std::submdspan_extents): Rename to... (std::subextents): Renamed from submdspan_extents. (std::submdspan_canonicalize_slices): Rename to... (std::canonical_slices): Renamed from submdspan_canonicalize_slices. * testsuite/23_containers/mdspan/submdspan/submdspan_canonicalize_slices.cc: Move to... * testsuite/23_containers/mdspan/submdspan/canonical_slices.cc: ...here. Updated calls to submdspan_canonicalize_slices. * testsuite/23_containers/mdspan/submdspan/submdspan_canonicalize_slices_neg.cc: Move to... * testsuite/23_containers/mdspan/submdspan/canonical_slices_neg.cc: ...here. Updated calls to submdspan_canonicalize_slices. * testsuite/23_containers/mdspan/submdspan/submdspan_extents.cc: Move to... * testsuite/23_containers/mdspan/submdspan/subextents.cc: ...here. Qualified and renamed calls to submdspan_extents. * testsuite/23_containers/mdspan/submdspan/submdspan_extents_neg.cc: Move to... * testsuite/23_containers/mdspan/submdspan/subextents_neg.cc: ...here. Qualified and renamed calls to submdspan_extents. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com> |
||
|
|
642020ab7e |
libstdc++: implement formatter for std::filesystem::path
This patch implements formatting for std::filesystem::path from P2845R8, and defines the feature test macro __cpp_lib_format_path to 202403L, provided only in <filesystem>. Formatting options are performed (if applicable) in order: 'g', '?', transcoding, fill-and-align & width The standard specifies transcoding behaviour only when literal encoding is UTF-8, leaving all other cases implementation defined. Current implementation of filesystem::path assumes: * char encoding is UTF-8 * wchar_t encoding is either UTF-32 or UTF-16 libstdc++-v3/ChangeLog: * include/bits/fs_path.h: Include bits/formatfwd.h. (std::formatter<filesystem::path, _CharT>): Define. * include/bits/version.def (format_path): Define. * include/bits/version.h: Regenerate. * include/std/filesystem: Expose __cpp_lib_format_path. * testsuite/std/format/fs_path.cc: New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Ivan Lazaric <ivan.lazaric1@gmail.com> Co-authored-by: Jonathan Wakely <jwakely@redhat.com> |
||
|
|
7bafcc3617 |
libstdc++: Make CTAD ignore tuple(const Types&...) constructor [PR121771]
This is similar to the r16-3536-g0bb0d1d2880d56 change for std::pair, so that CTAD ignores the tuple(const Types&...) constructor and only uses the tuple(Types...) -> tuple<Types...> deduction guide. This ensures that the deduced type comes from the decayed argument types. libstdc++-v3/ChangeLog: PR libstdc++/121771 * include/std/tuple (tuple::tuple(const Elements&...)): Use type_identity_t to prevent constructor being used for CTAD. (tuple::tuple(allocator_arg_t, const A&, const Elements&...)): Likewise. * testsuite/20_util/tuple/cons/121771.cc: New test. Reviewed-by: Ville Voutilainen <ville.voutilainen@gmail.com> |
||
|
|
0852c2d9d7 |
libstdc++/regex: Avoid -Wunused-parameter warnings in _Executor
Now that _Executor is non-recursive most subroutines no longer use their _Match_mode parameter (previously it was just passed to recursive _M_dfs calls). For now, just make them unnamed to avoid warnings. libstdc++-v3/ChangeLog: * include/bits/regex_executor.tcc (_Executor::_M_rep_once_more): Make unnused _Match_mode parameter unnamed. (_Executor::_M_handle_repeat): Likewise. (_Executor::_M_handle_subexpr_begin): Likewise. (_Executor::_M_handle_subexpr_end): Likewise. (_Executor::_M_handle_line_begin_assertion): Likewise. (_Executor::_M_handle_line_end_assertion): Likewise. (_Executor::_M_handle_match): Likewise. (_Executor::_M_handle_backref): Likewise. (_Executor::_M_handle_alternative): Likewise. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> |
||
|
|
db072f75e5 |
libstdc++: Fix fallback definitions of std::is_member_*_pointer
When the builtins aren't used we need a declaration of std::is_function for the fallback definitions of std::is_member_function_pointer and std::is_member_object_pointer. libstdc++-v3/ChangeLog: * include/std/type_traits (is_function): Declare before first use. |
||
|
|
48f2e8aa6d |
libstdc++: Clear padding bits in std::atomic ctor in C++11 [PR114865]
After the front end change r16-7199 both GCC and Clang allow non-empty constexpr constructor bodies in C++11 as an extension, so we can now unconditionally enable the __builtin_clear_padding logic in std::atomic's constructor. PR libstdc++/114865 libstdc++-v3/ChangeLog: * include/std/atomic (atomic<_Tp>::atomic(_Tp)) [C++11]: Enable __builtin_clear_padding logic. * testsuite/29_atomics/atomic/compare_exchange_padding.cc: Enable this test in earlier modes, including C++11. * testsuite/29_atomics/atomic/cons/zero_padding.cc [C++11]: Enable tests verifying cleared padding bits for a non-static-init std::atomic object. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com> |
||
|
|
b58cf25443 |
libstdc++: Make function_ref non-dangling for stateless wrappers
This patch makes the function_ref non-dangling for the stateless
wrappers:
* any functor for which operator() selected for arguments is static,
* standard functors, including pre-C++20 ones.
In other words, any function_ref fr, that is constructed from stateless
wrapper w, can be still called after the object w is destroyed, e.g.:
std::function_ref<bool(int, int)> fr(std::ranges::less{});
fr(1, 2); // OK, previously UB because fr referred to already destroyed
// temporary
As function_ref's operator() is not constexpr, we test the change by checking
if the above declaration can be made constexpr, as such variable cannot contain
dangling pointer values.
We adjust the function_ref generic constructor from any functor, to use more
specialized invoker:
* _S_static (newly added) if the called operator() overload is static,
after changes r16-5624-g0ea9d760fbf44c, this covers all post-c++20 functors;
* _S_nttp<_Fd{}> for pre-C++20 standard functors.
In both above cases the value of _M_ptrs is ignored and simply set to nullptr.
This follows same technique (checking _Fd::operator()(args...)), and support
the same set of types, as for one used for the transform views iterators in
r16-5625-g9ed821d107f7a1.
As after this change we provide well-defined behavior for the code, that
previous was undefined, this changes is pure quality-of-implementation.
As illustrated by the test cases, it has observable side effects, where
non-longer dangling constructs can be used to define constexpr function_ref.
However, the standard does not define when the constructors defined constexpr
are actually usable at compile time, and the already have precedent in form
of SSO string for validity such constructs being implementation specific.
libstdc++-v3/ChangeLog:
* include/bits/funcref_impl.h (function_ref::function_ref(_Fn&&)):
Use _S_static and _S_nttp invokers.
* include/bits/funcwrap.h (_Base_invoker::_S_static):
Define.
* include/bits/stl_function.h (std::__is_std_op_template)
(std::__is_std_op_wrapper) [__cplusplus > 201703L]:
Moved from std/ranges.
* include/std/ranges (__detail::__is_std_op_template)
(__detail::__is_std_op_wrapper): Moved to bits/stl_function.h.
* testsuite/20_util/function_ref/dangling.cc: New test.
* testsuite/20_util/function_ref/dangling_neg.cc: New test.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
|
||
|
|
fba29a5e4e |
libstdc++: Optimize std::regex_traits lookup functions
Optimize regex_traits::lookup_collatename and regex_traits::lookup_classname. For lookup_collatename we can hoist the static array into a non-dependent function, then call that for the regex_traits<char> specialization without performing any narrowing operations via the ctype facet. For the regex_traits<wchar_t> specialization we populate a std::string for the narrowed result, and call the non-dependent function. For lookup_classname we can avoid the static array entirely, replacing the iteration over that array with a nested switch that implements a kind of manually-unrolled trie, only match one char at a time until we either match a full string or get a mismatch. This avoids narrowing the entire input and storing it in a temporary string. This improves performance by 2-3x for -O2 and below (the benefit is much smaller for -O3). We can also check the input length for random access iterators, and reject any strings longer than "xdigit" without doing any work at all. For silly cases like [:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:] this gives a 100x improvement. libstdc++-v3/ChangeLog: * include/bits/regex.tcc (__detail::__lookup_collatename): New function. (regex_traits::lookup_collatename): Use new function. Elide redundant narrowing via ctype facet for regex_traits<char>. (regex_traits::lookup_classname): Replace lookup table with handwritten prefix match. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> |
||
|
|
49d219a5d7 |
libstdc++: Fix std::regex_traits::lookup_classname [PR124015]
This fixes a bug in regex_traits::lookup_classname(f, l, true) where the result was always ctype_base::alpha for any input sequence [f, l) that has the ctype_base::lower or ctype_base::upper bits set. For targets that define alpha as lower|upper (rather than having a distinct bit for alpha) this bug meant that all masks which have lower or upper bits set were replaced with alpha when the icase parameter is true. This has the effect that trying to do a case insensitive match for [:alnum:], [:graph:], or [:print:] was equivalent to matching [:alpha:] instead, which is obviously not correct. Based on inspection of the ctype_base.h files under the config/os directory, the bug appears to affect newlib, picolibc, qnx and vxworks. libstdc++-v3/ChangeLog: PR libstdc++/124015 * include/bits/regex.tcc (regex_traits::lookup_classname): Fix handling of icase parameter. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> |
||
|
|
6b550d69fe |
libstdc++: Allow constant initialization of std::atomic of types with padding [PR123875]
Currently for the types T that contains padding bits, std::atomic<T>(T) constructor was not usable at compile-time in C++14 or later modes. This regression caused by use of __builtin_clear_padding introduced in r13-2548-g157236dbd62164. This leads to two regressions when switching from C++11 to C++14 standard (or switching from GCC-12 to later version for C++14 standard), where for type X that contains padding * constexpr std::atomic<X> cx(X(...)) becomes ill-formed, * std::atomic<X> gx(X(...)) with static storage duration, switch from static to dynamic initialization. The latter breakage is silent and may introduced very hard to localize order of initialization issues. This patch mitigates above issue by not invoking the __builtin_clear_padding, during constant initialization (std::__is_constant_evaluated() is false). This is considered to be safe, as: * for objects with static storage duration, padding bits are already cleared by zero-initialization * for constexpr objects with non-static storage duration, there is no API that would allow user to observe padding bits on const atomic objects To elaborate on the second point, values of padding bits in atomic can be observed by: * The compare_exchange_weak/compare_exchange_strong operations are mutating, so cannot be invoked on const objects. * As atomic<X> is not required to store actual object of type X, observing its object representation does (via bitcast, memcpy), does not provide values of object representation of X. Furthermore, the operations are defined only for trivially_copyable types, and atomic specializations meets above requirement only due to bug in libstdc++ (see PR67572). Note that above will no longer hold, and the solution will need to be revisited during implementation of C++26 paper P3309R3: constexpr atomic and atomic_ref (it will be possible to call compare_exchange during constant evaluation). PR libstdc++/123875 libstdc++-v3/ChangeLog: * include/bits/atomic_base.h (__atomic_impl::__clear_padding): Use if constexpr unconditionally. (__atomic_float<_Fp>::__atomic_float(_Fp)): Skip __clear_padding call for constant evaluation. * include/std/atomic (atomic<_Tp>::atomic(_Tp)): Likewise. * testsuite/29_atomics/atomic/cons/static_zero_padding.cc: New test. Reviewed-by: Patrick Palka <ppalka@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com> |
||
|
|
0912dfcd1e |
libstdc++: Fix incorrect noexcept on string::compare overloads [PR123991]
These compare overloads throw when the pos index is out of range, not only when the const T& parameter throws on conversion to string_view. Remove the incorrect conditional noexcept-specifier from the two overloads that can throw. libstdc++-v3/ChangeLog: PR libstdc++/123991 * include/bits/basic_string.h (compare(size_type, size_type, T)): Remove noexcept-specifier. (compare(size_type, size_type, T, size_type, size_type)): Likewise. * include/bits/cow_string.h (compare(size_type, size_type, T)): Remove noexcept-specifier. (compare(size_type, size_type, T, size_type, size_type)): Likewise. * testsuite/21_strings/basic_string/operations/compare/char/123991.cc: New test. * testsuite/21_strings/basic_string/operations/compare/wchar_t/123991.cc: New test. Reviewed-by: Nathan Myers <nmyers@redhat.com> |
||
|
|
d3af40eefa |
libstdc++/regex: Remove now unused __dfs_mode template parameter
This mechanical patch removes _Executor's __dfs_mode template parameter. In passing we can also get rid of the _V2 inline namespace because this removal alone achieve the goal of the inline namespace which is to make all of _Executor's member function signatures different from the previous (GCC < 16) recursive implementation, allowing for safe mixing of the two incompatible implementations. libstdc++-v3/ChangeLog: * include/bits/regex.h (_Executor): Remove __dfs_mode template parameter and _V2 inline namespace. * include/bits/regex.tcc (__regex_algo_impl): Adjust after __dfs_mode template parameter removal. * include/bits/regex_executor.h (_Executor): Remove __dfs_mode parameter and _V2 inline namespace. * include/bits/regex_executor.tcc (_Executor): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com> |
||
|
|
c49ce07bf0 |
libstdc++/regex: Replace __dfs_mode template parameter with run-time flag
That _Executor's __dfs_mode flag is a template parameter means
__regex_algo_impl has to instantiate two different (but largely the
same) versions of _Executor even though the BFS version is rarely used.
And it seems the compiler has trouble DCEing the unused version of
_Executor, which needlessly increases code size and burdens the optimizer.
This patch replaces the template parameter with a run-time data member
_M_search_mode. We in turn need to inline the _Executor::_State_info
member functions and data members into _Executor so that they depend on
the run-time instead of compile-time flag. This means _Executor is
three pointers bigger in DFS mode (due to the unused _M_match_queue and
_M_visited_states members), which we can reduce to one pointer if we
really want to, but that doesn't seem ver worthwhile.
The __dfs_mode template parameter is now unused but not yet removed,
that'll be done in the next patch.
After this patch, both code size and run time for the microbenchmark
for (int i = 0; i < 10000; i++)
regex_match(string(200, 'a'), regex("(a|b|c)*"));
decreases by about 15% each (with -O2). Compile time/memory use decreases
by 5-10%.
libstdc++-v3/ChangeLog:
* include/bits/regex.tcc (__regex_algo_impl): Pass __use_dfs
parameter to _Executor's constructor.
* include/bits/regex_executor.h (_Executor::_Search_mode): New.
(_Executor::_Executor): Add __use_dfs parameter and initialize
_M_search_mode. Adjust after inlining _State_info members into
_Executor.
(_Executor::~_Executor): Free _M_visted_states.
(_Executor::_M_main): Adjust after renaming _M_main_dispatch
overloads to _M_main_dfs and _M_main_bfs.
(_Executor::_State_info): Remove.
(_Executor::_M_visited): Inlined from _State_info.
(_Executor::_M_get_sol_pos): Likewise.
(_Executor::_M_states): Remove.
(_Executor::_M_start): Inlined from _State_info.
(_Executor::_M_sol_pos): Likewise.
(_Executor::_M_match_queue): Likewise.
(_Executor::_M_search_mode): New.
* include/bits/regex_executor.tcc (_Executor::_M_main_dispatch):
Renamed to...
(_Executor::_M_main_dfs, _Executor::_M_main_bfs): ... these.
(_Executor::_M_*): Adjust after _M_states removal.
(_Executor::_M_lookhead): Also adjust _Executor constructor
call.
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
|
||
|
|
a53eaa2690 |
libstdc++: Fix doxygen comment for std::out_ptr [PR124024]
libstdc++-v3/ChangeLog: PR libstdc++/124024 * include/bits/out_ptr.h (out_ptr): Fix doxygen comment to refer to the right function. (inout_ptr): Improve markup in doxygen comment. |
||
|
|
9b85fcc00e |
libstdc++: Update guards on __heterogeneous_hash_key and __heterogeneous_tree_key
The r16-7359-gae04c1afd1526a changed __heterogeneous_key to be defined if __glibcxx_associative_heterogeneous_erasure, but missed guards on derived __heterogeneous_hash_key and __heterogeneous_tree_key concept. libstdc++-v3/ChangeLog: * include/bits/hashtable.h (std::__heterogeneous_hash_key) [__glibcxx_associative_heterogeneous_erasure]: Changed guard. * include/bits/stl_tree.h (std::__heterogeneous_tree_key) [__glibcxx_associative_heterogeneous_erasure]: Likewise. * include/bits/stl_function.h: Add comment with C++ version for __glibcxx_associative_heterogeneous_erasure guard. |
||
|
|
ae04c1afd1 |
libstdc++: fix C++17 regression in concept __heterogeneous_key (2nd)
The commit
|
||
|
|
786e316de5 |
libstdc++: fix C++17 regression in concept __heterogeneous_key
The commit
|
||
|
|
d78b2b6c01 |
libstdc++: make __collatenames array const in regex.tcc
libstdc++-v3/ChangeLog: * include/bits/regex.tcc (regex_traits::lookup_collatename): Make __collatenames array const. Signed-off-by: Caolán McNamara <caolanm@gmail.com> |
||
|
|
269ce3de8c |
libstdc++: Fix ambiguity caused by new std::source_location constructor
The new constructor added for Contracts support was not explicit, so caused ambiguities when arbitrary pointers were used in contexts which could convert to std::source_location. We don't actually need a constructor, the contract_violation::location() function can just set the data member directly. libstdc++-v3/ChangeLog: * include/std/contracts (contract_violation::location): Use source_location default constructor and then set _M_impl. * include/std/source_location (source_location(const void*)): Remove constructor. * testsuite/18_support/contracts/includes.cc: Move to... * testsuite/18_support/contracts/srcloc.cc: ...here. Test for ambiguity caused by new constructor. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> |
||
|
|
3f79055504 |
libstdc++: container erasure overloads (P2077) [PR117404]
Remaining to do: * Add new declarations in debug headers too. Implement C++23 P2077R3 "Heterogeneous erasure overloads for associative containers". Adds template overloads for members erase and extract to address elements using an alternative key type, such as string_view for a container of strings, without need to construct an actual key object. The new overloads enforce concept __heterogeneous_tree_key or __heterogeneous_hash_key to verify the function objects provided meet requirements, and that the key supplied is not an iterator or the native key. libstdc++-v3/ChangeLog: PR libstdc++/117404 * include/bits/version.def (associative_heterogeneous_erasure): Define. * include/bits/version.h: Regenerate. * include/std/map: Request new feature from version.h. * include/std/set: Same. * include/std/unordered_map: Same. * include/std/unordered_set: Same. * include/bits/stl_map.h (extract, erase): Define overloads. * include/bits/stl_set.h: Same. * include/bits/stl_multimap.h: Same. * include/bits/stl_multiset.h: Same. * include/bits/unordered_map.h: Same, 2x. * include/bits/unordered_set.h: Same, 2x. * include/bits/stl_function.h (concepts __not_container_iterator, __heterogeneous_key): Define. * include/bits/hashtable.h (_M_find_before_node, _M_locate, extract): Delegate to more-general _tr version. (_M_find_before_node_tr, _M_locate_tr, _M_extract_tr, _M_erase_tr): Add new members to support a heterogeneous key argument. (_M_erase_some): Add new helper function. (concept __heterogeneous_hash_key): Define. * include/bits/stl_tree.h (_M_lower_bound_tr, _M_upper_bound_tr, _M_erase_tr, _M_extract_tr): Add new members to support a heterogeneous key argument. (concept __heterogeneous_tree_key): Define. * testsuite/23_containers/map/modifiers/hetero/erase.cc: New test. * testsuite/23_containers/multimap/modifiers/hetero/erase.cc: Same. * testsuite/23_containers/multiset/modifiers/hetero/erase.cc: Same. * testsuite/23_containers/set/modifiers/hetero/erase.cc: Same. * testsuite/23_containers/unordered_map/modifiers/hetero/erase.cc: Same. * testsuite/23_containers/unordered_multimap/modifiers/hetero/erase.cc: Same. * testsuite/23_containers/unordered_multiset/modifiers/hetero/erase.cc: Same. * testsuite/23_containers/unordered_set/modifiers/hetero/erase.cc: Same. |
||
|
|
7197d0cce7 |
libstdc++, c++/reflection: mark {,de}allocate constexpr
[allocator.members] says that allocator::{,de}allocate should be
constexpr but currently we don't mark them as such. I had to
work around that in the Reflection code, but it would be better to
clean this up. (I see no allocation_result so I'm not changing that.)
gcc/cp/ChangeLog:
* constexpr.cc (is_std_allocator): Don't check for __new_allocator.
(is_std_allocator_allocate): Make static.
* cp-tree.h (is_std_allocator_allocate): Remove declaration.
* reflect.cc (check_out_of_consteval_use): Don't call
is_std_allocator_allocate.
(check_consteval_only_fn): Likewise.
libstdc++-v3/ChangeLog:
* include/bits/new_allocator.h (__new_allocator::allocate,
__new_allocator::deallocate): Add missing constexpr.
Reviewed-by: Jason Merrill <jason@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
|
||
|
|
4a514ea759 |
libstdc++: Define __cpp_lib_define_static [PR123921]
I've totally missed the P3491R3 paper (define_static_{string,object,array})
comes with its own feature test macro - __cpp_lib_define_static 202506
which should appear in <version> and <meta>.
The paper contains 3 parts, std::is_string_literal,
std::meta::reflect_constant_{string,array} and
std::define_static_{string,object,array}.
The first part is implementable without reflection, the third part in theory
would be also implementable without reflection but usually will be (and in
libstdc++ is) implemented using reflection, and the middle part is really
part of reflection. So dunno how useful this FTM actually is, maybe just
for cases where some implementation does implement reflection and doesn't
implement this paper for a while.
Anyway, the FTM is in C++26 draft, so this patch adds it, with the same
condition as __cpp_lib_reflection.
2026-02-03 Jakub Jelinek <jakub@redhat.com>
PR libstdc++/123921
* include/bits/version.def (define_static): New with the
same values as reflection.
* include/bits/version.h: Regenerate.
* include/std/meta: Define also __glibcxx_want_define_static before
including bits/version.h.
* g++.dg/reflect/feat2.C: Add also test for __cpp_lib_define_static.
* g++.dg/reflect/feat3.C: New test.
|
||
|
|
8978da072f |
libstdc++/regex: Zero-initialize _ExecutorFrame flags
Prevents uninitialized read bugs, and it's also just natural to assume flags are initially cleared rather than uninitialized. In passing rename the _M_end flag to _M_subexpr_end to make it distinct from _Executor::_M_end. libstdc++-v3/ChangeLog: * include/bits/regex_executor.tcc (_ExecutorFrameBase): Zero-initialize _M_byte0. (_ExecutorFrameBase::_M_end): Rename to ... (_ExecutorFrameBase::_M_subexpr_end): ... this. (_Executor::_M_handle_subexpr_begin): Remove now redundant clearing of _M_subexpr_end. (_Executor::_M_handle_subexpr_end): Adjust after renaming. (_Executor::_M_dfs) <case _S_fopcode_restore_cur_results>: Likewise. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> |
||
|
|
bdd45f4eee |
libstdc++/regex: Suppress -Wpedantic warning about anonymous structs
Fixes some modules testsuite compilation errors. libstdc++-v3/ChangeLog: * include/bits/regex_executor.tcc (_ExecutorFrameBase): Add #pragma GCC diagnostic to suppress -Wpedantic warning about anonymous structs. |
||
|
|
a8a1183d58 |
libstdc++/regex: add [[gnu::always_inline]] to _Executor::_M_node
The compiler understandably doesn't know that _M_node only ever has a single call site, _M_dfs, (and is not directly called from other library headers or user code) and so decides not to inline it. So use the always_inline attribute to force the inlining. This seems sufficient to make all _M_dfs subroutines get inlined away, and speeds up the executor by 30% on some microbenchmarks. libstdc++-v3/ChangeLog: * include/bits/regex_executor.tcc (__detail::_Executor::_M_node) [__OPTIMIZE__]: Add [[gnu::always_inline]] attribute. Declare inline. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> |
||
|
|
ead66d5f22 |
libstdc++/regex: Defer _M_current restoration to backtracking nodes [PR86164]
The incrementing of the current input string position (_M_current) is done by _M_handle_match, which also makes sure to restore it afterwards, via a restore_current frame. But restoring _M_current is naturally only necessary when backtracking is involved, not after every single match. So this patch moves the responsibility of saving/restoring _M_current from _M_handle_match to the branching nodes _M_handle_alternative and _M_handle_repeat. This is done by storing _M_current within the fallback_next, fallback_rep_once_more and posix_alternative frames. In turn we can get rid of the now unused restore_current frame kind. This reduces the maximum size of the _M_frames stack by 15% for regex_match(string(200000, 'a'), "(a|b|c)*") PR libstdc++/86164 libstdc++-v3/ChangeLog: * include/bits/regex_executor.tcc (__detail::_ExecutorFrameOpcode): Remove _S_fopcode_restore_current. (__detail::_Executor::_M_handle_repeat): Pass _M_current when pushing a fallback_next or fallback_rep_once_more frame. (__detail::_Executor::_M_handle_match): Don't push a restore_current frame. (__detail::_Executor::_M_handle_backref): Likewise and simplify accordingly. (__detail::_Executor::_M_handle_alternative): Pass _M_current when pushing a fallback_next or posix_alternative frame. (__detail::_Executor::_M_dfs) <case _S_fopcode_fallback_next>: Restore _M_current. <case _S_fopcode_fallback_rep_once_more>: Likewise. <case _S_fopcode_posix_alternative>: Likewise. <case _S_fopcode_restore_current>: Remove. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com> |
||
|
|
158ad5f969 |
libstdc++/regex: Make DFS executor non-recursive [PR86164]
This patch replaces the recursive implementation of the DFS executor with an iterative one using an explicit heap-based stack. System stack usage of the executor is now constant with respect to input size rather than linear, avoding stack overflow errors when processing long inputs. PR libstdc++/86164 libstdc++-v3/ChangeLog: * include/bits/regex.h (__detail::_Executor): Use inline namespace _V2. * include/bits/regex_executor.h (__detail::_ExecutorFrame): Declare. (__detail::_Executor): Use inline namespace _V2. (__detail::_Executor::_M_node): Declare. (__detail::_Executor::_M_frames): New data member. * include/bits/regex_executor.tcc (__detail::_ExecutorFrameOpcode): New. (__detail::_ExecutorFrameBase): New. (__detail::_ExecutorFrame): New. (__detail::_Executor): Use inline namespace _V2. (__detail::_Executor::_M_rep_once_more): Replace recursive _M_dfs calls with an _S_opcode_next frame push, and any work after such calls with an appropriate frame push. (__detail::_M_handle_repeat): Likewise. (__detail::_M_handle_subexpr_begin): Likewise. (__detail::_M_handle_subexpr_end): Likewise. (__detail::_M_handle_line_begin_assertion): Likewise. (__detail::_M_handle_line_end_assertion): Likewise. (__detail::_M_handle_word_boundary): Likewise. (__detail::_M_handle_subexpr_lookahead): Likewise. (__detail::_M_handle_match): Likewise. (__detail::_M_handle_backref): Likewise. (__detail::_M_handle_accept): Likewise. (__detail::_M_handle_alternative): Likewise. (__detail::_M_node): Factored out from _M_dfs. (__detail::_M_dfs): Push an initial frame to _M_frames that visits the starting node and pass this stack each subroutine. Pop the latest _ExecutorFrame from _M_frames and handle appropriately according to its _ExecutorFrameOpcode. Loop until _M_frames is empty. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com> |
||
|
|
57f571f728 |
libstdc++: Make std::expected trivially copy/move assignable (LWG 4026)
This is the subject of two NB comments on C++26 which seem likely to be approved. We're allowed to make this change as QoI anyway, even if it isn't approved for the standard, and it should apply to C++23 as well to avoid ABI changes between C++23 and C++26. As shown in the updates to the test, defaulted special members can have noexcept(false) even if they would be noexcept(true) by default. The new defaulted operator= overloads added by this commit have conditional noexcept-specifiers that match the conditions of the non-trivial assignments, propagating any noexcept(false) on trivial special members of the T and E types. We could strengthen the noexcept for the trivial operators, but propagating the conditions from the underlying types is probably what users expect, if they've bothered to put noexcept(false) on their defaulted special members. libstdc++-v3/ChangeLog: * include/std/expected (__expected::__trivially_replaceable) (__expected::__usable_for_assign) (__expected::__usable_for_trivial_assign) (__expected::__can_reassign_type): New concepts. (expected::operator=): Adjust constraints on existing overloads and add defaulted overload. (expected<cv void, E>::operator=): Likewise. * testsuite/20_util/expected/requirements.cc: Check for trivial and nothrow properties of assignments. |
||
|
|
a111fd4d47 |
libstdc++: Fix use of feature test macro in <source_location>
libstdc++-v3/ChangeLog: * include/std/source_location: Check __glibcxx_contracts instead of __cpp_lib_contracts. * testsuite/18_support/contracts/includes.cc: New test. |
||
|
|
95ed4da229 |
libstdc++: Fix non-ASCII characters in <contracts> header
This fixes: FAIL: 17_intro/headers/c++1998/charset.cc -std=gnu++26 (test for excess errors) libstdc++-v3/ChangeLog: * include/std/contracts: Replace non-ASCII characters. |
||
|
|
f362763f62 |
libstdc++: Do not allow contract26.cc to build without -fcontracts
It seems prefereable to get a hard error if this file is built incorrectly, rather than failing to define any symbols. libstdc++-v3/ChangeLog: * src/experimental/contract26.cc: Use #error if built without contracts support enabled. * include/std/source_location: Remove stray whitespace. |
||
|
|
74e0bb3faa |
libstdc++: Disable false positive middle end warnings in std::shared_ptr [PR122197]
Speculative devirtualization in GCC 16 causes some false positive warnings for unreachable paths. Use diagnostic pragmas to suppress those warnings until the regression is fixed. libstdc++-v3/ChangeLog: PR tree-optimization/122197 * include/bits/shared_ptr_base.h (~_Sp_counted_deleter): Use diagnostic pragam to disable -Wfree-nonheap-object false positive. (~_Sp_counted_ptr_inplace): Likewise for -Warray-bounds false positive. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> |
||
|
|
68a1218c18 |
libstdc++: Implement std::atomic::fetch_min/max
This patch extends libstdc++ to implement C++26's atomic fetch min/max operations. The __atomic_fetch_minmaxable concept checks if __atomic_fetch_min and __atomic_fetch_max builtins are implemented by the compiler. If not, fall back to a CAS loop. This patch was bootstrapped and regtested on aarch64-linux-gnu and x86_64-linux-gnu, no regression. Signed-off-by: Soumya AR <soumyaa@nvidia.com> libstdc++-v3/ChangeLog: * include/bits/atomic_base.h: Add fetch_min and fetch_max memberfunctions. * include/bits/version.def: Add __cpp_lib_atomic_min_max feature test macro. * include/bits/version.h (defined): Regenerate. * include/std/atomic: Extend for fetch_min/max non-member functions. * src/c++23/std.cc.in: Export atomic_fetch_min, atomic_fetch_max, atomic_fetch_min_explicit, atomic_fetch_max_explicit. * testsuite/29_atomics/atomic_integral/nonmembers_fetch_minmax.cc: New test. * testsuite/29_atomics/atomic_ref/integral_fetch_minmax.cc: New test. |
||
|
|
fbde291af6 |
libstdc++, contracts: Add base P2900R14 contracts support.
What we need to do here (and, of course, in the code synthesis that produces the objects) needs to be interoperable with other platforms that share ABI. For the present, this means Itanium and to interoperate with clang and libc++. The model we have followed in the development is essentially the same as the model used for the C++2a edition. However there is some concern that the read-only data footprint of this is potentially high and alternate schemes are in discussion with the clang folks. Since the layout of the violation object is ABI let's leave this in experimental until an agreed solution is fixed. Remove the cxx2a support at the same time, GCC no longer supports this mode. libstdc++-v3/ChangeLog: * include/Makefile.am: Add contract include. * include/Makefile.in: Regenerate. * include/bits/version.def: Add ftm for contracts. * include/bits/version.h: Regenerate. * include/precompiled/stdc++.h: Add contracts header. * include/std/source_location: Befriend the contract_violation class so that we can initialise a source_location from an existing __impl *. * src/c++23/std.cc.in: Add contracts support. * src/experimental/Makefile.am: Add new contract violation implementation, remove the old one. * src/experimental/Makefile.in: Regenerate. * include/experimental/contract: Removed. * src/experimental/contract.cc: Removed. * include/std/contracts: New file. * src/experimental/contract26.cc: New file. * testsuite/18_support/contracts/invoke_default_cvh.cc: New test. * testsuite/18_support/contracts/invoke_default_cvh2.cc: New test. Co-Authored-by: Iain Sandoe <iain@sandoe.co.uk> Co-Authored-by: Ville Voutilainen <ville.voutilainen@gmail.com> Signed-off-by: Nina Ranns <dinka.ranns@gmail.com> |
||
|
|
d7e5113e59 |
libstdc++: Explicitly call _Mo_base() in _Cpy_base copy-constructor [PR123758]
This silences the warning while preserving current (correct) behavior. PR libstdc++/123758 libstdc++-v3/ChangeLog: * include/bits/funcwrap.h (_Cpy_base(_Cpy_base const&)): Explicitly call _Mo_base() in initializer list. |
||
|
|
23cd6f3bcb |
libstdc++: Disable __cpp_lib_reflection for old CXX ABI
Reflection currently doesn't work with -D_GLIBCXX_USE_CXX11_ABI=0.
The problem is that std::meta::exception currently uses under the
hood std::string and std::u8string and those aren't constexpr in
the old ABI.
While those members are in the standard exposition-only and so
we could make it to work by writing a custom class template that
just remembers const char{,8_t} * and size_t, there shouldn't be
many people trying to use C++26 features with the ABI that isn't
even compatible with C++11.
2026-01-20 Jakub Jelinek <jakub@redhat.com>
* include/bits/version.def (reflection): Add cxx11abi = yes;.
* include/bits/version.h: Regenerate.
|
||
|
|
8fad43b785 |
libstdc++: Use overload operator<=> when provided in relational functors [PR114153]
The implementation of less<> did not consider the possibility of t < u being
rewritten from overloaded operator<=>. This lead to situation when for t,u that:
* provide overload operator<=>, such that (t < u) is rewritten to (t <=> u) < 0,
* are convertible to pointers,
the expression std::less<>(t, u) would incorrectly result in call of
std::less<void*> on values converted to the pointers, instead of t < u.
The similar issues also occurred for greater<>, less_equal<>, greater_equal<>,
their range equivalents, and in three_way_compare for heterogeneous calls.
This patch addresses above, by also checking for free-functions and member
overloads of operator<=>, before falling back to pointer comparison. We do
not put any constraints on the return type of selected operator, in particular
in being one of the standard defined comparison categories, as the language
does not put any restriction of returned type, and if (t <=> u) is well
formed, (t op u) is interpreted as (t <=> u) op 0. If that later expression
is ill-formed, the expression using op also is (see included tests).
The relational operator rewrites try both order of arguments, t < u,
can be rewritten into operator<=>(t, u) < 0 or 0 < operator<=>(u, t), it
means that we need to test both operator<=>(T, U) and operator<=>(U, T)
if T and U are not the same types. This is now extracted into
__not_overloaded_spaceship helper concept, placed in <concepts>, to
avoid extending set of includes.
The compare_three_way functor defined in compare, already considers overloaded
operator<=>, however it does not consider reversed candidates, leading
to situation in which t <=> u results in 0 <=> operator<=>(u, t), while
compare_three_way{}(t, u) uses pointer comparison. This is also addressed by
using __not_overloaded_spaceship, that check both order of arguments.
Finally, as operator<=> is introduced in C++20, for std::less(_equal)?<>,
std::greater(_equal)?<>, we use provide separate __ptr_cmp implementation
in that mode, that relies on use of requires expression. We use a nested
requires clause to guarantee short-circuiting of their evaluation.
The operator() of aforementioned functors is reworked to use if constexpr,
in all standard modes (as we allow is as extension), eliminating the need
for _S_cmp function.
PR libstdc++/114153
libstdc++-v3/ChangeLog:
* include/bits/ranges_cmp.h (__detail::__less_builtin_ptr_cmp):
Add __not_overloaded_spaceship spaceship check.
* include/bits/stl_function.h (greater<void>::operator())
(less<void>::operator(), greater_equal<void>::operator())
(less_equal<void>::operator()): Implement using if constexpr.
(greater<void>::__S_cmp, less<void>::__S_cmp)
(greater_equal<void>::__ptr_comp, less_equal<void>::S_cmp):
Remove.
(greater<void>::__ptr_cmp, less<void>::__ptr_cmp)
(greater_equal<void>::__ptr_comp, less_equal<void>::ptr_cmp): Change
tostatic constexpr variable. Define in terms of requires expressions
and __not_overloaded_spaceship check.
* include/std/concepts: (__detail::__not_overloaded_spaceship):
Define.
* libsupc++/compare: (__detail::__3way_builtin_ptr_cmp): Use
__not_overloaded_spaceship concept.
* testsuite/20_util/function_objects/comparisons_pointer_spaceship.cc: New test.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
|
||
|
|
e9a62938be |
libstdc++: Fix std::erase_if for std::string with -D_GLIBCXX_USE_CXX11_ABI=0.
The __cow_string used with -D_GLIBCXX_USE_CXX11_ABI=0, does not provide erase accepting const_iterator, so we adjust __detail::__erase.if (introduced in r16-6889-g3287) to call __cont.erase with mutable iterators. libstdc++-v3/ChangeLog: * include/bits/erase_if.h (__detail::__erase_if): Pass mutable iterators to __cont.erase. |
||
|
|
3287a5c617 |
libstdc++: Fix std::erase_if behavior for std::__debug containers
Complete fix of std::erase_if/std::erase for all std::__debug containers and __gnu_debug::basic_string. Make sure that iterators erased by this function will be properly detected as such by the debug container and so considered as invalid. Doing so introduce a new std::__detail::__erase_if function dealing, similarly to std::__detail::__erase_node_if, with non-node containers. libstdc++-v3/ChangeLog: * include/bits/erase_if.h (__detail::__erase_if): New. * include/debug/deque (std::erase_if<>(__debug::deque<>&, _Pred)): Use latter. * include/debug/inplace_vector (std::erase_if<>(__debug::inplace_vector<>&, _Pred)): Likewise. * include/debug/vector (std::erase_if<>(__debug::vector<>&, _Pred)): Likewise. * include/std/deque: Include erase_if.h. (std::erase_if<>(std::vector<>&, _Pred)): Adapt to use __detail::__erase_if. * include/std/inplace_vector (std::erase_if<>(std::inplace_vector<>&, _Pred)): Likewise. * include/std/string (std::erase_if<>(std::basic_string<>&, _Pred)): Likewise. * include/std/vector (std::erase_if<>(std::vector<>&, _Pred)): Likewise. * include/debug/forward_list (std::erase_if<>(__debug::forward_list<>&, _Pred)): New. (std::erase<>(__debug::forward_list<>&, const _Up&)): New. * include/debug/list (std::erase_if<>(__debug::list<>&, _Pred)): New. (std::erase<>(__debug::list<>&, const _Up&)): New. * include/debug/map (std::erase_if<>(__debug::map<>&, _Pred)): New. (std::erase_if<>(__debug::multimap<>&, _Pred)): New. * include/debug/set (std::erase_if<>(__debug::set<>&, _Pred)): New. (std::erase_if<>(__debug::multiset<>&, _Pred)): New. * include/debug/string (std::erase_if<>(__gnu_debug::basic_string<>&, _Pred)): New. (std::erase<>(__gnu_debug::basic_string<>&, const _Up&)): New. * include/debug/unordered_map (std::erase_if<>(__debug::unordered_map<>&, _Pred)): New. (std::erase_if<>(__debug::unordered_multimap<>&, _Pred)): New. * include/debug/unordered_set (std::erase_if<>(__debug::unordered_set<>&, _Pred)): New. (std::erase_if<>(__debug::unordered_multiset<>&, _Pred)): New. * include/std/forward_list (std::erase_if<>(std::forward_list<>&, _Pred)): Adapt to work exclusively for normal implementation. (std::erase<>(std::forward_list<>&, const _Up&)): Likewise. * include/std/list (std::erase_if<>(std::list<>&, _Pred)): Likewise. (std::erase<>(std::list<>&, const _Up&)): Likewise. * include/std/map (std::erase_if<>(std::map<>&, _Pred)): Likewise. (std::erase_if<>(std::multimap<>&, _Pred)): Likewise. Guard functions using __cpp_lib_erase_if. * include/std/set (std::erase_if<>(std::set<>&, _Pred)): Likewise. (std::erase_if<>(std::multiset<>&, _Pred)): Likewise. Guard functions using __cpp_lib_erase_if. * include/std/unordered_map (std::erase_if<>(std::unordered_map<>&, _Pred)): Likewise. (std::erase_if<>(std::unordered_multimap<>&, _Pred)): Likewise. Guard functions using __cpp_lib_erase_if. * include/std/unordered_set (std::erase_if<>(std::unordered_set<>&, _Pred)): Likewise. (std::erase_if<>(std::unordered_multiset<>&, _Pred)): Likewise. Guard functions using __cpp_lib_erase_if. * testsuite/21_strings/basic_string/debug/erase.cc: New test case. * testsuite/23_containers/forward_list/debug/erase.cc: New test case. * testsuite/23_containers/forward_list/debug/invalidation/erase.cc: New test case. * testsuite/23_containers/list/debug/erase.cc: New test case. * testsuite/23_containers/list/debug/invalidation/erase.cc: New test case. * testsuite/23_containers/map/debug/erase_if.cc: New test case. * testsuite/23_containers/map/debug/invalidation/erase_if.cc: New test case. * testsuite/23_containers/multimap/debug/erase_if.cc: New test case. * testsuite/23_containers/multimap/debug/invalidation/erase_if.cc: New test case. * testsuite/23_containers/multiset/debug/erase_if.cc: New test case. * testsuite/23_containers/multiset/debug/invalidation/erase_if.cc: New test case. * testsuite/23_containers/set/debug/erase_if.cc: New test case. * testsuite/23_containers/set/debug/invalidation/erase_if.cc: New test case. * testsuite/23_containers/unordered_map/debug/erase_if.cc: New test case. * testsuite/23_containers/unordered_map/debug/invalidation/erase_if.cc: New test case. * testsuite/23_containers/unordered_multimap/debug/erase_if.cc: New test case. * testsuite/23_containers/unordered_multimap/debug/invalidation/erase_if.cc: New test case. * testsuite/23_containers/unordered_multiset/debug/erase_if.cc: New test case. * testsuite/23_containers/unordered_multiset/debug/invalidation/erase_if.cc: New test case. * testsuite/23_containers/unordered_set/debug/erase_if.cc: New test case. * testsuite/23_containers/unordered_set/debug/invalidation/erase_if.cc: New test case. |
||
|
|
dc716fb66a |
libstdc++: Fix __cpp_impl_reflection comparisons
Last night when applying Marek's patchset for testing I've noticed I forgot to change these 5 spots when changing the -freflection -std=c++26 predefined value from 202500 which meant we implement some reflection, but not the whole paper, to 202506 which is the https://eel.is/c++draft/tab:cpp.predefined.ft value for it. 2026-01-15 Jakub Jelinek <jakub@redhat.com> * include/std/type_traits (std::is_reflection, std::is_fundamental, std::is_reflection_v, std::is_consteval_only): Compare __cpp_impl_reflection >= 202506L instead of 202500L. * testsuite/20_util/variable_templates_for_traits.cc: Likewise. |
||
|
|
4b0e94b394 |
c++: C++26 Reflection [PR120775]
This patch implements C++26 Reflection as specified by P2996R13, which allows
users to perform magic. This patch also implements related papers:
Annotations for Reflection (P3394R4),
Splicing a base class subobject (P3293R3),
define_static_{string,object,array} (P3491R3),
Function Parameter Reflection (P3096R12).
(I already implemented consteval blocks back in July.)
(We do not yet implement P3795.)
We also implemented some CWG issues that had been approved in Kona;
e.g., CWG 3101, 3109, 3111, 3115, 3117.
All metafunctions are implemented in this patch.
The feature needs to be enabled by -std=c++26 -freflection.
Some stats: the v1 patch was over 51,200 LOC which were written in ~335
commits. It came with over 400 tests with 11,722 static_asserts. We still
had about 50 TODOs and FIXMEs in the code.
v2 consists of about 56,000 LOC which were created in 440 commits. We
now have 446 tests with 40 TODOs remaining.
v3 brought another 77 commits, mostly clean-ups and various bug fixes.
I'd like to thank:
Jakub Jelinek, whose efforts can only be described as heroic and who
never ceases to amaze me even after nearly 15 years of working together,
he implemented many difficult metafunctions, annotations, mangling,
converted our metafunction dispatch to using gperf, and so on and on;
Jonathan Wakely for his libstdc++ patch review and generous & impeccable
advice even at odd hours; Dan Katz for his work on the Reflection papers,
writing Reflection tests for clang++ (many of which I've stolen^Wused),
for his advice, bug reports, and generally cheering me on; Jason Merrill
for his guidance, patch review, and, in fact, encouraging me to take on
this project in the first place; Michael Levine, Valentyn Yukhymenko, and
Alex Yesmanchyk for their nice contributions to Reflection; and Tomasz
Kamiński for providing test cases, finding bugs, and answering my C++
questions.
PR c++/120775
PR c++/123081
PR c++/122634
gcc/ChangeLog:
* attribs.cc (attribute_value_equal): Return false if either attribute
is ATTR_UNIQUE_VALUE_P.
(merge_attributes): Handle lists with ATTR_UNIQUE_VALUE_P values.
* doc/invoke.texi: Document -freflection.
* dwarf2out.cc (is_base_type) <case default>: Check
TREE_CODE >= LAST_AND_UNUSED_TREE_CODE instead of is_cxx_auto.
(gen_type_die_with_usage): For TREE_CODE >= LAST_AND_UNUSED_TREE_CODE
trees use use DW_TAG_unspecified_type.
* tree-core.h (struct tree_base): Update a comment.
* tree.h (ATTR_UNIQUE_VALUE_P): Define.
(BINFO_BASE_ACCESSES): Update the comment.
gcc/c-family/ChangeLog:
* c-attribs.cc (attribute_takes_identifier_p): Return false for C++
annotations. Handle "old parm name".
* c-cppbuiltin.cc (c_cpp_builtins): Define __cpp_impl_reflection.
* c.opt (freflection): New.
gcc/cp/ChangeLog:
* Make-lang.in: Add cp/reflect.o. Add a rule for cp/metafns.h.
* config-lang.in: Add reflect.cc.
* constexpr.cc (constexpr_global_ctx): Add consteval_block and
metafns_called members. Initialize them.
(cxx_constexpr_quiet_p): New.
(cxx_constexpr_manifestly_const_eval): New.
(cxx_constexpr_caller): New.
(cxx_constexpr_consteval_block): New.
(enum value_cat): Move into cp-tree.h.
(cxx_eval_constant_expression): Move the declaration into cp-tree.h.
No longer static. Handle REFLECT_EXPR. Handle conversion of
a reflection to the meta::info type.
(cxx_eval_cxa_builtin_fn): Override current_function_decl.
(cxx_eval_builtin_function_call): Handle __builtin_is_string_literal.
(is_std_allocator): Also check __new_allocator.
(is_std_allocator_allocate): No longer static.
(cxa_allocate_and_throw_exception): New.
(cxx_eval_call_expression): Handle metafunctions. Maybe set
metafns_called.
(reduced_constant_expression_p): Handle REFLECT_EXPR.
(cxx_eval_binary_expression): Use compare_reflections for comparing
reflections.
(find_immediate_fndecl): Don't walk REFLECT_EXPR_P.
(cxx_eval_outermost_constant_expr): Set global_ctx.consteval_block.
Detect consteval-only smuggling.
(potential_constant_expression_1): Return true for REFLECT_EXPR
and SPLICE_EXPR.
* constraint.cc (diagnose_trait_expr): Add CPTK_IS_CONSTEVAL_ONLY case.
* cp-gimplify.cc (immediate_escalating_function_p): No longer static.
(promote_function_to_consteval): Likewise.
(cp_gimplify_expr) <case CALL_EXPR>: Detect any surviving consteval-only
expressions.
<case CP_BUILT_IN_IS_STRING_LITERAL>: Handle.
(wipe_consteval_only_r): New.
(cp_fold_immediate_r): Detect invalid uses of consteval-only types.
Clear consteval-only DECL_EXPRs.
(cp_genericize_r): Wipe consteval-only vars from BIND_EXPR_VARS and
BLOCK_VARS.
* cp-objcp-common.cc (cp_common_init_ts): Mark META_TYPE, SPLICE_SCOPE,
SPLICE_EXPR, and REFLECT_EXPR.
* cp-trait.def (IS_CONSTEVAL_ONLY): New trait.
* cp-tree.def (REFLECT_EXPR, META_TYPE, SPLICE_EXPR, SPLICE_SCOPE): New
trees.
* cp-tree.h (enum cp_tree_index): Add CPTI_ANNOTATION_IDENTIFIER,
CPTI_STD_META, and CPTI_META_INFO_TYPE.
(std_meta_node): Define.
(meta_info_type_node): Define.
(annotation_identifier): Define.
(REFLECTION_TYPE_P): Define.
(REFLECT_EXPR_P): Define.
(REFLECT_EXPR_HANDLE): Define.
(enum reflect_kind): New.
(REFLECT_EXPR_KIND): Define.
(SET_REFLECT_EXPR_KIND): Define.
(SPLICE_EXPR_EXPRESSION_P): Define.
(SET_SPLICE_EXPR_EXPRESSION_P): Define.
(SPLICE_EXPR_MEMBER_ACCESS_P): Define.
(SET_SPLICE_EXPR_MEMBER_ACCESS_P): Define.
(SPLICE_EXPR_ADDRESS_P): Define.
(SET_SPLICE_EXPR_ADDRESS_P): Define.
(SPLICE_SCOPE_EXPR): Define.
(SPLICE_SCOPE_TYPE_P): Define.
(WILDCARD_TYPE_P): Include SPLICE_SCOPE.
(COMPONENT_REF_SPLICE_P): Define.
(SCALAR_TYPE_P): Include REFLECTION_TYPE_P.
(ENUM_BEING_DEFINED_P): Define.
(OLD_PARM_DECL_P): Define.
(MULTIPLE_NAMES_PARM_P): Define.
(cp_preserve_using_decl): Declare.
(DEF_OPERATOR, DEF_ASSN_OPERATOR): Include META.
(struct ovl_op_info_t): Add meta_name member.
(enum cp_built_in_function): Add CP_BUILT_IN_IS_STRING_LITERAL.
(build_stub_type): Declare.
(current_function_decl_without_access_scope): Declare.
(dependent_namespace_p): Declare.
(convert_reflect_constant_arg): Declare.
(finish_base_specifier): Adjust declaration.
(parsing_lambda_declarator): Declare.
(fold_builtin_is_string_literal): Declare.
(annotation_p): Declare.
(finish_class_member_access_expr): Adjust declaration.
(immediate_escalating_function_p): Declare.
(promote_function_to_consteval): Declare.
(is_std_allocator_allocate): Declare.
(cxa_allocate_and_throw_exception): Declare.
(enum value_cat): Define.
(cxx_eval_constant_expression): Declare.
(cxx_constexpr_quiet_p): Declare.
(cxx_constexpr_manifestly_const_eval): Declare.
(cxx_constexpr_caller): Declare.
(cxx_constexpr_consteval_block): Declare.
(init_reflection): Declare.
(metafunction_p): Declare.
(direct_base_parent): Declare.
(process_metafunction): Declare.
(get_reflection): Declare.
(get_null_reflection): Declare.
(splice): Declare.
(check_out_of_consteval_use): Declare.
(consteval_only_p): Declare.
(compare_reflections): Declare.
(valid_splice_type_p): Declare.
(valid_splice_scope_p): Declare.
(check_splice_expr): Declare.
(make_splice_scope): Declare.
(dependent_splice_p): Declare.
(reflection_mangle_prefix): Declare.
(check_consteval_only_fn): Declare.
* cvt.cc (convert_to_void): Call check_out_of_consteval_use.
* cxx-pretty-print.cc (cxx_pretty_printer::unary_expression): New
REFLECT_EXPR case.
(cxx_pretty_printer::expression): Likewise.
(cxx_pretty_printer::simple_type_specifier): New META_TYPE case.
(cxx_pretty_printer::type_id): Likewise.
* decl.cc (duplicate_decls): Merge parameter names for Reflection.
Maybe set OLD_PARM_DECL_P.
(initialize_predefined_identifiers): Add "annotation ".
(cxx_init_decl_processing): Add __builtin_is_string_literal. Call
init_reflection.
(maybe_commonize_var): Do nothing for consteval_only_p.
(check_initializer): Default-initialize std::meta::info.
(make_rtl_for_nonlocal_decl): For consteval_only_p vars, set
DECL_EXTERNAL and return early.
(cp_finish_decl): Call check_out_of_consteval_use. Don't go
creating a varpool node for consteval_only_p.
(get_tuple_size): Check the instantiation instead of the type.
(grokfndecl): Call check_consteval_only_fn.
(xref_basetypes): Stitch annotations onto BINFO_BASE_ACCESSES.
(finish_enum_value_list): Clear ENUM_BEING_DEFINED_P.
* decl2.cc (is_late_template_attribute): Handle all annotations as
late.
(cp_check_const_attributes): Don't handle annotations here.
(maybe_make_one_only): Do nothing for consteval_only_p.
(mark_needed): Likewise.
(min_vis_expr_r): Handle reflections.
(prune_vars_needing_no_initialization): Skip consteval_only_p.
(no_linkage_error): Return early for metafunctions.
(c_parse_final_cleanups): Don't write out consteval_only_p vars. Avoid
complaining about metafunctions.
* error.cc (dump_type): New cases for CONST_DECL, META_TYPE, and
SPLICE_SCOPE.
(dump_type_prefix): New cases for META_TYPE and SPLICE_SCOPE.
(dump_type_suffix): Likewise.
(dump_decl): Dump SPLICE_EXPR.
(dump_expr): Dump REFLECT_EXPR and SPLICE_EXPR.
* init.cc (build_zero_init_1): Build a null reflection value.
(perform_member_init): Call check_out_of_consteval_use.
* lex.cc (DEF_OPERATOR, OPERATOR_TRANSITION): Update defines.
* mangle.cc (write_type): Mangle META_TYPE.
(write_expression): Handle REFLECT_EXPR.
(write_reflection): New.
(write_template_arg_literal): New REFLECT_EXPR case.
(write_template_arg): Handle REFLECT_EXPR.
* method.cc (build_stub_type): No longer static.
* module.cc (trees_out::type_node): Handle META_TYPE.
(trees_in::tree_node): Likewise.
* name-lookup.cc (name_lookup::adl_type): std::meta is an associated
namespace of std::meta::info.
(strip_using_decl): Don't strip when cp_preserve_using_decl.
(handle_namespace_attrs): Handle annotations.
(do_namespace_alias): Handle SPLICE_EXPR.
(lookup_qualified_name): When cp_preserve_using_decl, don't do
OVL_FUNCTION.
(finish_using_directive): Detect annotations on using directive.
* operators.def: Update for META_NAME.
* parser.cc: New cp_preserve_using_decl global.
(enum required_token): Add RT_CLOSE_SPLICE.
(get_required_cpp_ttype): Return CPP_CLOSE_SPLICE for RT_CLOSE_SPLICE.
(cp_parser_next_tokens_start_splice_type_spec_p): New.
(cp_parser_next_tokens_can_start_splice_scope_spec_p): New.
(cp_parser_splice_specifier): New.
(cp_parser_splice_type_specifier): New.
(cp_parser_splice_expression): New.
(cp_parser_splice_scope_specifier): New.
(cp_parser_splice_spec_is_nns_p): New.
(cp_parser_nth_token_starts_splice_without_nns_p): New.
(cp_parser_primary_expression): Handle CPP_OPEN_SPLICE. Give an
error for ^^ outside reflection.
(cp_parser_unqualified_id): Allow r.~typename [:R:].
(cp_parser_nested_name_specifier_opt): Cope with splice-scope-specifier.
(cp_parser_qualifying_entity): Parse splice-scope-specifier.
(cp_parser_postfix_expression): Deal with [: :] after a typename.
(cp_parser_postfix_dot_deref_expression): Parse & handle splices
in a class member access. Pass splice_p to
finish_class_member_access_expr.
(cp_parser_reflection_name): New.
(cp_parser_reflect_expression): New.
(cp_parser_unary_expression): Parse reflect-expression.
(cp_parser_declaration): Parse splice-scope-specifier.
(cp_parser_decomposition_declaration): Detect annotations on structured
bindings.
(cp_parser_decltype_expr): Parse splice-expression.
(cp_parser_template_id): New parsed_templ argument. If it's nonnull,
don't parse the template name. Turn an assert into a condition.
(cp_parser_type_specifier): Handle typename [: :].
(cp_parser_simple_type_specifier): Parse splice-type-specifier.
(cp_parser_enum_specifier): Set ENUM_BEING_DEFINED_P.
(cp_parser_namespace_alias_definition): Parse splice-specifier.
(cp_parser_using_directive): Likewise.
(cp_parser_type_id_1): New bool * parameter to distinguish between
types and type aliases. Set it.
(cp_parser_type_id): Adjust the call to cp_parser_type_id_1.
(cp_parser_template_type_arg): Likewise.
(cp_parser_trailing_type_id): Likewise.
(cp_parser_base_specifier): Handle annotations. Maybe give an error
for splice-scope-specifier. Parse splice-type-specifier. Pass
annotations to finish_base_specifier.
(cp_parser_annotation): New.
(cp_parser_std_attribute_list): Detect mixing annotations and attributes
in the same list.
(cp_parser_annotation_list): New.
(cp_parser_std_attribute_spec): Parse annotations.
(cp_parser_skip_balanced_tokens): Also handle CPP_OPEN_SPLICE
and CPP_CLOSE_SPLICE.
(cp_parser_type_requirement): Parse splice-type-specifier.
(cp_parser_lookup_name): Also consider dependent namespaces. Don't
call check_accessibility_of_qualified_id for USING_DECLs.
(cp_parser_required_error): Handle RT_CLOSE_SPLICE.
* pt.cc (current_function_decl_without_access_scope): New.
(verify_unstripped_args_1): REFLECT_EXPR_P is OK.
(iterative_hash_template_arg): Handle REFLECT_EXPR.
(convert_nontype_argument): Maybe give an error for REFLECTION_TYPE_P.
(for_each_template_parm_r): Handle SPLICE_SCOPE.
(instantiate_class_template): Handle annotations.
(tsubst_pack_index): Make static.
(tsubst_decl): Handle NAMESPACE_DECL.
(tsubst_splice_scope): New.
(tsubst_splice_expr): New.
(tsubst): Don't return early for NAMESPACE_DECL. New META_TYPE case.
Handle a splice-specifier that expanded into a NAMESPACE_DECL. Handle
SPLICE_SCOPE, SPLICE_EXPR, and TEMPLATE_ID_EXPR.
(tsubst_scope): Also accept NAMESPACE_DECL.
(tsubst_qualified_id): Check dependent_namespace_p.
(tsubst_lambda_expr): Set LAMBDA_EXPR_CONSTEVAL_BLOCK_P.
(tsubst_expr): Allow dependent_splice_p in an assert. Check
COMPONENT_REF_SPLICE_P and pass it to finish_class_member_access_expr.
<case NAMESPACE_DECL>: Remove.
New REFLECT_EXPR and SPLICE_EXPR cases.
(unify): Handle META_TYPE.
(instantiate_body): Call check_consteval_only_fn.
(tsubst_enum): Set ENUM_BEING_DEFINED_P.
(dependent_type_p_r): A splice-scope-specifier is dependent.
(dependent_namespace_p): New.
(value_dependent_expression_p): Handle REFLECT_EXPR. Also handle
[meta.reflection.access.context]/8.
(type_dependent_expression_p): REFLECT_EXPR_P is not type-dependent.
(convert_reflect_constant_arg): New.
* search.cc (check_final_overrider): Adjust for CWG 3117.
* semantics.cc (finish_base_specifier): Handle annotations.
(parsing_lambda_declarator): No longer static.
(finish_id_expression_1): Check dependent_namespace_p.
(fold_builtin_is_string_literal): New.
(trait_expr_value): Handle CPTK_IS_CONSTEVAL_ONLY.
(finish_trait_expr): Likewise.
* tree.cc (handle_annotation_attribute): New.
(builtin_valid_in_constant_expr_p): Return true for
CP_BUILT_IN_IS_STRING_LITERAL.
(cp_tree_equal): Handle comparing REFLECT_EXPRs.
(internal_attributes): Add "annotation ".
(annotation_p): New.
* typeck.cc (finish_class_member_access_expr): New splice_p argument.
Handle dependent splices. Implement splicing a base class subobject.
Handle class member access using a splice-expression.
(cp_build_binary_op): Handle comparing std::meta::infos.
(check_return_expr): Call check_out_of_consteval_use.
* metafns.gperf: New file.
* metafns.h: New file.
* reflect.cc: New file.
libcc1/ChangeLog:
* libcp1plugin.cc (start_class_def): Update the call to
finish_base_specifier.
libcpp/ChangeLog:
* charset.cc (_cpp_destroy_iconv): Destroy narrow_cset_desc and
utf8_cset_desc.
(cpp_translate_string): New.
(cpp_valid_identifier): New.
* include/cpplib.h: Add OPEN_SPLICE, CLOSE_SPLICE, and REFLECT_OP to
TTYPE_TABLE.
(cpp_translate_string): Declare.
(cpp_valid_identifier): Declare.
* internal.h (struct cpp_reader): Add reverse_narrow_cset_desc and
reverse_utf8_cset_desc fields.
* lex.cc (_cpp_lex_direct): Emit CPP_CLOSE_SPLICE, CPP_REFLECT_OP,
and CPP_OPEN_SPLICE tokens.
libstdc++-v3/ChangeLog:
* include/Makefile.am (std_headers): Add ${std_srcdir}/meta.
* include/Makefile.in: Regenerate.
* include/bits/iterator_concepts.h (std::ranges::__access::__begin): Add
constexpr.
* include/bits/version.def (reflection): New.
* include/bits/version.h: Regenerate.
* include/precompiled/stdc++.h: Include <meta> for C++26.
* include/std/meta: New file.
* include/std/type_traits (std::is_reflection): New trait.
(std::is_fundamental): Include is_reflection for C++26 -freflection.
(std::is_reflection_v): New variable template.
(std::is_consteval_only): New trait.
(std::is_consteval_only_v): New variable template.
* src/c++23/std.cc.in: Add <meta> exports.
* testsuite/20_util/variable_templates_for_traits.cc: Add -freflection as
dg-additional-options for C++26. Add std::is_reflection_v test in that case.
* testsuite/20_util/is_consteval_only/requirements/explicit_instantiation.cc: New test.
* testsuite/20_util/is_consteval_only/requirements/typedefs.cc: New test.
* testsuite/20_util/is_consteval_only/value.cc: New test.
* testsuite/20_util/is_reflection/requirements/explicit_instantiation.cc: New test.
* testsuite/20_util/is_reflection/requirements/typedefs.cc: New test.
* testsuite/20_util/is_reflection/value.cc: New test.
gcc/testsuite/ChangeLog:
* g++.dg/DRs/dr2581-1.C: Add -freflection.
* g++.dg/DRs/dr2581-2.C: Likewise.
* g++.dg/reflect/access_context1.C: New test.
* g++.dg/reflect/access_context2.C: New test.
* g++.dg/reflect/access_context3.C: New test.
* g++.dg/reflect/adl1.C: New test.
* g++.dg/reflect/alignment_of1.C: New test.
* g++.dg/reflect/alignment_of2.C: New test.
* g++.dg/reflect/annotations1.C: New test.
* g++.dg/reflect/annotations2.C: New test.
* g++.dg/reflect/annotations3.C: New test.
* g++.dg/reflect/annotations4.C: New test.
* g++.dg/reflect/annotations5.C: New test.
* g++.dg/reflect/annotations6.C: New test.
* g++.dg/reflect/annotations7.C: New test.
* g++.dg/reflect/annotations8.C: New test.
* g++.dg/reflect/anon1.C: New test.
* g++.dg/reflect/anon2.C: New test.
* g++.dg/reflect/anon3.C: New test.
* g++.dg/reflect/bases_of1.C: New test.
* g++.dg/reflect/bases_of2.C: New test.
* g++.dg/reflect/bases_of3.C: New test.
* g++.dg/reflect/bit_size_of1.C: New test.
* g++.dg/reflect/bitfield1.C: New test.
* g++.dg/reflect/can_substitute1.C: New test.
* g++.dg/reflect/class1.C: New test.
* g++.dg/reflect/class2.C: New test.
* g++.dg/reflect/common_reference1.C: New test.
* g++.dg/reflect/common_type1.C: New test.
* g++.dg/reflect/compare1.C: New test.
* g++.dg/reflect/compare10.C: New test.
* g++.dg/reflect/compare2.C: New test.
* g++.dg/reflect/compare3.C: New test.
* g++.dg/reflect/compare4.C: New test.
* g++.dg/reflect/compare5.C: New test.
* g++.dg/reflect/compare6.C: New test.
* g++.dg/reflect/compare7.C: New test.
* g++.dg/reflect/compare8.C: New test.
* g++.dg/reflect/compare9.C: New test.
* g++.dg/reflect/compat1.C: New test.
* g++.dg/reflect/complete1.C: New test.
* g++.dg/reflect/constant_of1.C: New test.
* g++.dg/reflect/constant_of2.C: New test.
* g++.dg/reflect/constant_of3.C: New test.
* g++.dg/reflect/constant_of4.C: New test.
* g++.dg/reflect/constant_of5.C: New test.
* g++.dg/reflect/constant_of6.C: New test.
* g++.dg/reflect/constant_of7.C: New test.
* g++.dg/reflect/constant_of8.C: New test.
* g++.dg/reflect/constant_of9.C: New test.
* g++.dg/reflect/crash1.C: New test.
* g++.dg/reflect/crash10.C: New test.
* g++.dg/reflect/crash11.C: New test.
* g++.dg/reflect/crash12.C: New test.
* g++.dg/reflect/crash13.C: New test.
* g++.dg/reflect/crash14.C: New test.
* g++.dg/reflect/crash15.C: New test.
* g++.dg/reflect/crash16.C: New test.
* g++.dg/reflect/crash17.C: New test.
* g++.dg/reflect/crash18.C: New test.
* g++.dg/reflect/crash2.C: New test.
* g++.dg/reflect/crash3.C: New test.
* g++.dg/reflect/crash4.C: New test.
* g++.dg/reflect/crash5.C: New test.
* g++.dg/reflect/crash6.C: New test.
* g++.dg/reflect/crash7.C: New test.
* g++.dg/reflect/crash8.C: New test.
* g++.dg/reflect/crash9.C: New test.
* g++.dg/reflect/data_member_spec1.C: New test.
* g++.dg/reflect/data_member_spec2.C: New test.
* g++.dg/reflect/data_member_spec3.C: New test.
* g++.dg/reflect/data_member_spec4.C: New test.
* g++.dg/reflect/dealias1.C: New test.
* g++.dg/reflect/dealias2.C: New test.
* g++.dg/reflect/dealias3.C: New test.
* g++.dg/reflect/define_aggregate1.C: New test.
* g++.dg/reflect/define_aggregate2.C: New test.
* g++.dg/reflect/define_aggregate3.C: New test.
* g++.dg/reflect/define_aggregate4.C: New test.
* g++.dg/reflect/define_aggregate5.C: New test.
* g++.dg/reflect/define_static_array1.C: New test.
* g++.dg/reflect/define_static_array2.C: New test.
* g++.dg/reflect/define_static_array3.C: New test.
* g++.dg/reflect/define_static_array4.C: New test.
* g++.dg/reflect/define_static_object1.C: New test.
* g++.dg/reflect/define_static_object2.C: New test.
* g++.dg/reflect/define_static_string1.C: New test.
* g++.dg/reflect/dep1.C: New test.
* g++.dg/reflect/dep10.C: New test.
* g++.dg/reflect/dep11.C: New test.
* g++.dg/reflect/dep2.C: New test.
* g++.dg/reflect/dep3.C: New test.
* g++.dg/reflect/dep4.C: New test.
* g++.dg/reflect/dep5.C: New test.
* g++.dg/reflect/dep6.C: New test.
* g++.dg/reflect/dep7.C: New test.
* g++.dg/reflect/dep8.C: New test.
* g++.dg/reflect/dep9.C: New test.
* g++.dg/reflect/diag1.C: New test.
* g++.dg/reflect/diag2.C: New test.
* g++.dg/reflect/diag3.C: New test.
* g++.dg/reflect/diag4.C: New test.
* g++.dg/reflect/display_string_of1.C: New test.
* g++.dg/reflect/eh1.C: New test.
* g++.dg/reflect/eh2.C: New test.
* g++.dg/reflect/eh3.C: New test.
* g++.dg/reflect/eh4.C: New test.
* g++.dg/reflect/eh5.C: New test.
* g++.dg/reflect/eh6.C: New test.
* g++.dg/reflect/eh7.C: New test.
* g++.dg/reflect/eh8.C: New test.
* g++.dg/reflect/eh9.C: New test.
* g++.dg/reflect/enumerators_of1.C: New test.
* g++.dg/reflect/error1.C: New test.
* g++.dg/reflect/error10.C: New test.
* g++.dg/reflect/error2.C: New test.
* g++.dg/reflect/error3.C: New test.
* g++.dg/reflect/error4.C: New test.
* g++.dg/reflect/error5.C: New test.
* g++.dg/reflect/error6.C: New test.
* g++.dg/reflect/error8.C: New test.
* g++.dg/reflect/error9.C: New test.
* g++.dg/reflect/expr1.C: New test.
* g++.dg/reflect/expr10.C: New test.
* g++.dg/reflect/expr11.C: New test.
* g++.dg/reflect/expr12.C: New test.
* g++.dg/reflect/expr13.C: New test.
* g++.dg/reflect/expr14.C: New test.
* g++.dg/reflect/expr2.C: New test.
* g++.dg/reflect/expr3.C: New test.
* g++.dg/reflect/expr4.C: New test.
* g++.dg/reflect/expr5.C: New test.
* g++.dg/reflect/expr6.C: New test.
* g++.dg/reflect/expr7.C: New test.
* g++.dg/reflect/expr8.C: New test.
* g++.dg/reflect/expr9.C: New test.
* g++.dg/reflect/extract1.C: New test.
* g++.dg/reflect/extract2.C: New test.
* g++.dg/reflect/extract3.C: New test.
* g++.dg/reflect/extract4.C: New test.
* g++.dg/reflect/extract5.C: New test.
* g++.dg/reflect/extract6.C: New test.
* g++.dg/reflect/extract7.C: New test.
* g++.dg/reflect/extract8.C: New test.
* g++.dg/reflect/extract9.C: New test.
* g++.dg/reflect/feat1.C: New test.
* g++.dg/reflect/feat2.C: New test.
* g++.dg/reflect/has_c_language_linkage1.C: New test.
* g++.dg/reflect/has_default_argument1.C: New test.
* g++.dg/reflect/has_default_argument2.C: New test.
* g++.dg/reflect/has_default_member_initializer1.C: New test.
* g++.dg/reflect/has_ellipsis_parameter1.C: New test.
* g++.dg/reflect/has_external_linkage1.C: New test.
* g++.dg/reflect/has_external_linkage2.C: New test.
* g++.dg/reflect/has_identifier1.C: New test.
* g++.dg/reflect/has_identifier2.C: New test.
* g++.dg/reflect/has_internal_linkage1.C: New test.
* g++.dg/reflect/has_internal_linkage2.C: New test.
* g++.dg/reflect/has_linkage1.C: New test.
* g++.dg/reflect/has_module_linkage1.C: New test.
* g++.dg/reflect/has_module_linkage2.C: New test.
* g++.dg/reflect/has_parent1.C: New test.
* g++.dg/reflect/has_template_arguments1.C: New test.
* g++.dg/reflect/has_template_arguments2.C: New test.
* g++.dg/reflect/has_template_arguments3.C: New test.
* g++.dg/reflect/has_template_arguments4.C: New test.
* g++.dg/reflect/identifier_of1.C: New test.
* g++.dg/reflect/identifier_of2.C: New test.
* g++.dg/reflect/init1.C: New test.
* g++.dg/reflect/init10.C: New test.
* g++.dg/reflect/init11.C: New test.
* g++.dg/reflect/init12.C: New test.
* g++.dg/reflect/init13.C: New test.
* g++.dg/reflect/init14.C: New test.
* g++.dg/reflect/init15.C: New test.
* g++.dg/reflect/init16.C: New test.
* g++.dg/reflect/init17.C: New test.
* g++.dg/reflect/init2.C: New test.
* g++.dg/reflect/init3.C: New test.
* g++.dg/reflect/init4.C: New test.
* g++.dg/reflect/init5.C: New test.
* g++.dg/reflect/init6.C: New test.
* g++.dg/reflect/init7.C: New test.
* g++.dg/reflect/init8.C: New test.
* g++.dg/reflect/init9.C: New test.
* g++.dg/reflect/is_accessible1.C: New test.
* g++.dg/reflect/is_accessible2.C: New test.
* g++.dg/reflect/is_alias_template1.C: New test.
* g++.dg/reflect/is_assignment1.C: New test.
* g++.dg/reflect/is_bit_field1.C: New test.
* g++.dg/reflect/is_class_member1.C: New test.
* g++.dg/reflect/is_class_template1.C: New test.
* g++.dg/reflect/is_complete_type1.C: New test.
* g++.dg/reflect/is_complete_type2.C: New test.
* g++.dg/reflect/is_concept1.C: New test.
* g++.dg/reflect/is_const1.C: New test.
* g++.dg/reflect/is_consteval_only1.C: New test.
* g++.dg/reflect/is_constructible_type1.C: New test.
* g++.dg/reflect/is_constructible_type2.C: New test.
* g++.dg/reflect/is_constructor_template1.C: New test.
* g++.dg/reflect/is_constuctor1.C: New test.
* g++.dg/reflect/is_conversion_function1.C: New test.
* g++.dg/reflect/is_conversion_function_template1.C: New test.
* g++.dg/reflect/is_copy_assignment1.C: New test.
* g++.dg/reflect/is_copy_constructor1.C: New test.
* g++.dg/reflect/is_data_member_spec1.C: New test.
* g++.dg/reflect/is_default_constructor1.C: New test.
* g++.dg/reflect/is_defaulted1.C: New test.
* g++.dg/reflect/is_defaulted2.C: New test.
* g++.dg/reflect/is_deleted1.C: New test.
* g++.dg/reflect/is_deleted2.C: New test.
* g++.dg/reflect/is_destructor1.C: New test.
* g++.dg/reflect/is_enumerable_type1.C: New test.
* g++.dg/reflect/is_enumerator1.C: New test.
* g++.dg/reflect/is_explicit1.C: New test.
* g++.dg/reflect/is_explicit2.C: New test.
* g++.dg/reflect/is_explicit_object_parameter1.C: New test.
* g++.dg/reflect/is_final1.C: New test.
* g++.dg/reflect/is_function1.C: New test.
* g++.dg/reflect/is_function2.C: New test.
* g++.dg/reflect/is_function3.C: New test.
* g++.dg/reflect/is_function_parameter1.C: New test.
* g++.dg/reflect/is_function_parameter2.C: New test.
* g++.dg/reflect/is_function_template1.C: New test.
* g++.dg/reflect/is_function_template2.C: New test.
* g++.dg/reflect/is_function_type1.C: New test.
* g++.dg/reflect/is_literal_operator1.C: New test.
* g++.dg/reflect/is_literal_operator_template1.C: New test.
* g++.dg/reflect/is_lrvalue_reference_qualified1.C: New test.
* g++.dg/reflect/is_move_assignment1.C: New test.
* g++.dg/reflect/is_move_constructor1.C: New test.
* g++.dg/reflect/is_mutable_member1.C: New test.
* g++.dg/reflect/is_namespace1.C: New test.
* g++.dg/reflect/is_namespace_alias1.C: New test.
* g++.dg/reflect/is_namespace_member1.C: New test.
* g++.dg/reflect/is_noexcept1.C: New test.
* g++.dg/reflect/is_noexcept2.C: New test.
* g++.dg/reflect/is_noexcept3.C: New test.
* g++.dg/reflect/is_noexcept4.C: New test.
* g++.dg/reflect/is_nonstatic_data_member1.C: New test.
* g++.dg/reflect/is_object1.C: New test.
* g++.dg/reflect/is_object2.C: New test.
* g++.dg/reflect/is_operator_function1.C: New test.
* g++.dg/reflect/is_operator_function_template1.C: New test.
* g++.dg/reflect/is_override1.C: New test.
* g++.dg/reflect/is_pure_virtual1.C: New test.
* g++.dg/reflect/is_special_member_function1.C: New test.
* g++.dg/reflect/is_static_member1.C: New test.
* g++.dg/reflect/is_string_literal1.C: New test.
* g++.dg/reflect/is_structured_binding1.C: New test.
* g++.dg/reflect/is_structured_binding2.C: New test.
* g++.dg/reflect/is_template1.C: New test.
* g++.dg/reflect/is_template2.C: New test.
* g++.dg/reflect/is_type1.C: New test.
* g++.dg/reflect/is_type_alias1.C: New test.
* g++.dg/reflect/is_type_alias2.C: New test.
* g++.dg/reflect/is_type_alias3.C: New test.
* g++.dg/reflect/is_user_declared1.C: New test.
* g++.dg/reflect/is_user_declared2.C: New test.
* g++.dg/reflect/is_user_provided1.C: New test.
* g++.dg/reflect/is_user_provided2.C: New test.
* g++.dg/reflect/is_variable1.C: New test.
* g++.dg/reflect/is_variable_template1.C: New test.
* g++.dg/reflect/is_virtual1.C: New test.
* g++.dg/reflect/is_volatile1.C: New test.
* g++.dg/reflect/lex1.C: New test.
* g++.dg/reflect/lex2.C: New test.
* g++.dg/reflect/mangle1.C: New test.
* g++.dg/reflect/member-visibility1.C: New test.
* g++.dg/reflect/member-visibility2.C: New test.
* g++.dg/reflect/member1.C: New test.
* g++.dg/reflect/member10.C: New test.
* g++.dg/reflect/member11.C: New test.
* g++.dg/reflect/member12.C: New test.
* g++.dg/reflect/member13.C: New test.
* g++.dg/reflect/member14.C: New test.
* g++.dg/reflect/member15.C: New test.
* g++.dg/reflect/member16.C: New test.
* g++.dg/reflect/member17.C: New test.
* g++.dg/reflect/member18.C: New test.
* g++.dg/reflect/member19.C: New test.
* g++.dg/reflect/member2.C: New test.
* g++.dg/reflect/member20.C: New test.
* g++.dg/reflect/member3.C: New test.
* g++.dg/reflect/member4.C: New test.
* g++.dg/reflect/member5.C: New test.
* g++.dg/reflect/member6.C: New test.
* g++.dg/reflect/member7.C: New test.
* g++.dg/reflect/member8.C: New test.
* g++.dg/reflect/member9.C: New test.
* g++.dg/reflect/members_of1.C: New test.
* g++.dg/reflect/members_of2.C: New test.
* g++.dg/reflect/members_of3.C: New test.
* g++.dg/reflect/members_of4.C: New test.
* g++.dg/reflect/members_of5.C: New test.
* g++.dg/reflect/members_of6.C: New test.
* g++.dg/reflect/members_of7.C: New test.
* g++.dg/reflect/metafn-ptr1.C: New test.
* g++.dg/reflect/ns1.C: New test.
* g++.dg/reflect/ns2.C: New test.
* g++.dg/reflect/ns3.C: New test.
* g++.dg/reflect/ns4.C: New test.
* g++.dg/reflect/ns5.C: New test.
* g++.dg/reflect/ns6.C: New test.
* g++.dg/reflect/null1.C: New test.
* g++.dg/reflect/null2.C: New test.
* g++.dg/reflect/null3.C: New test.
* g++.dg/reflect/null4.C: New test.
* g++.dg/reflect/null5.C: New test.
* g++.dg/reflect/object_of1.C: New test.
* g++.dg/reflect/object_of2.C: New test.
* g++.dg/reflect/odr1.C: New test.
* g++.dg/reflect/offset_of1.C: New test.
* g++.dg/reflect/operator_of1.C: New test.
* g++.dg/reflect/override1.C: New test.
* g++.dg/reflect/p2996-1.C: New test.
* g++.dg/reflect/p2996-10.C: New test.
* g++.dg/reflect/p2996-11.C: New test.
* g++.dg/reflect/p2996-12.C: New test.
* g++.dg/reflect/p2996-13.C: New test.
* g++.dg/reflect/p2996-14.C: New test.
* g++.dg/reflect/p2996-15.C: New test.
* g++.dg/reflect/p2996-16.C: New test.
* g++.dg/reflect/p2996-17.C: New test.
* g++.dg/reflect/p2996-18.C: New test.
* g++.dg/reflect/p2996-19.C: New test.
* g++.dg/reflect/p2996-2.C: New test.
* g++.dg/reflect/p2996-20.C: New test.
* g++.dg/reflect/p2996-21.C: New test.
* g++.dg/reflect/p2996-3.C: New test.
* g++.dg/reflect/p2996-4.C: New test.
* g++.dg/reflect/p2996-5.C: New test.
* g++.dg/reflect/p2996-6.C: New test.
* g++.dg/reflect/p2996-7.C: New test.
* g++.dg/reflect/p2996-8.C: New test.
* g++.dg/reflect/p2996-9.C: New test.
* g++.dg/reflect/p3394-1.C: New test.
* g++.dg/reflect/p3491-1.C: New test.
* g++.dg/reflect/p3491-2.C: New test.
* g++.dg/reflect/p3491-3.C: New test.
* g++.dg/reflect/pack-index1.C: New test.
* g++.dg/reflect/parameters_of1.C: New test.
* g++.dg/reflect/parameters_of2.C: New test.
* g++.dg/reflect/parameters_of3.C: New test.
* g++.dg/reflect/parameters_of4.C: New test.
* g++.dg/reflect/parameters_of5.C: New test.
* g++.dg/reflect/parameters_of6.C: New test.
* g++.dg/reflect/parent_of1.C: New test.
* g++.dg/reflect/parm1.C: New test.
* g++.dg/reflect/parm2.C: New test.
* g++.dg/reflect/parm3.C: New test.
* g++.dg/reflect/parm4.C: New test.
* g++.dg/reflect/pr122634-1.C: New test.
* g++.dg/reflect/pr122634-2.C: New test.
* g++.dg/reflect/qrn1.C: New test.
* g++.dg/reflect/qrn2.C: New test.
* g++.dg/reflect/range_args.C: New test.
* g++.dg/reflect/reflect_constant1.C: New test.
* g++.dg/reflect/reflect_constant2.C: New test.
* g++.dg/reflect/reflect_constant3.C: New test.
* g++.dg/reflect/reflect_constant4.C: New test.
* g++.dg/reflect/reflect_constant5.C: New test.
* g++.dg/reflect/reflect_constant6.C: New test.
* g++.dg/reflect/reflect_constant7.C: New test.
* g++.dg/reflect/reflect_constant8.C: New test.
* g++.dg/reflect/reflect_constant9.C: New test.
* g++.dg/reflect/reflect_constant_array1.C: New test.
* g++.dg/reflect/reflect_constant_array2.C: New test.
* g++.dg/reflect/reflect_constant_array3.C: New test.
* g++.dg/reflect/reflect_constant_array4.C: New test.
* g++.dg/reflect/reflect_constant_string1.C: New test.
* g++.dg/reflect/reflect_constant_string2.C: New test.
* g++.dg/reflect/reflect_function1.C: New test.
* g++.dg/reflect/reflect_function2.C: New test.
* g++.dg/reflect/reflect_object1.C: New test.
* g++.dg/reflect/reflect_object2.C: New test.
* g++.dg/reflect/reflect_object3.C: New test.
* g++.dg/reflect/reflect_object4.C: New test.
* g++.dg/reflect/return_type_of1.C: New test.
* g++.dg/reflect/return_type_of2.C: New test.
* g++.dg/reflect/serialize1.C: New test.
* g++.dg/reflect/serialize2.C: New test.
* g++.dg/reflect/size_of1.C: New test.
* g++.dg/reflect/source_location_of1.C: New test.
* g++.dg/reflect/source_location_of2.C: New test.
* g++.dg/reflect/splice1.C: New test.
* g++.dg/reflect/splice2.C: New test.
* g++.dg/reflect/splice3.C: New test.
* g++.dg/reflect/splice4.C: New test.
* g++.dg/reflect/splice5.C: New test.
* g++.dg/reflect/splice6.C: New test.
* g++.dg/reflect/splice7.C: New test.
* g++.dg/reflect/splicing-base1.C: New test.
* g++.dg/reflect/splicing-base2.C: New test.
* g++.dg/reflect/splicing-base3.C: New test.
* g++.dg/reflect/splicing-base4.C: New test.
* g++.dg/reflect/storage_duration1.C: New test.
* g++.dg/reflect/storage_duration2.C: New test.
* g++.dg/reflect/storage_duration3.C: New test.
* g++.dg/reflect/subobjects_of1.C: New test.
* g++.dg/reflect/substitute1.C: New test.
* g++.dg/reflect/substitute2.C: New test.
* g++.dg/reflect/symbol_of1.C: New test.
* g++.dg/reflect/symbol_of2.C: New test.
* g++.dg/reflect/template_arguments_of1.C: New test.
* g++.dg/reflect/template_arguments_of2.C: New test.
* g++.dg/reflect/template_arguments_of3.C: New test.
* g++.dg/reflect/template_of1.C: New test.
* g++.dg/reflect/template_of2.C: New test.
* g++.dg/reflect/template_of3.C: New test.
* g++.dg/reflect/tuple1.C: New test.
* g++.dg/reflect/tuple2.C: New test.
* g++.dg/reflect/type1.C: New test.
* g++.dg/reflect/type10.C: New test.
* g++.dg/reflect/type2.C: New test.
* g++.dg/reflect/type3.C: New test.
* g++.dg/reflect/type4.C: New test.
* g++.dg/reflect/type5.C: New test.
* g++.dg/reflect/type6.C: New test.
* g++.dg/reflect/type7.C: New test.
* g++.dg/reflect/type8.C: New test.
* g++.dg/reflect/type9.C: New test.
* g++.dg/reflect/type_of1.C: New test.
* g++.dg/reflect/type_of2.C: New test.
* g++.dg/reflect/type_rels1.C: New test.
* g++.dg/reflect/type_trait1.C: New test.
* g++.dg/reflect/type_trait10.C: New test.
* g++.dg/reflect/type_trait11.C: New test.
* g++.dg/reflect/type_trait12.C: New test.
* g++.dg/reflect/type_trait13.C: New test.
* g++.dg/reflect/type_trait2.C: New test.
* g++.dg/reflect/type_trait3.C: New test.
* g++.dg/reflect/type_trait4.C: New test.
* g++.dg/reflect/type_trait5.C: New test.
* g++.dg/reflect/type_trait6.C: New test.
* g++.dg/reflect/type_trait8.C: New test.
* g++.dg/reflect/type_trait9.C: New test.
* g++.dg/reflect/u8display_string_of1.C: New test.
* g++.dg/reflect/u8identifier_of1.C: New test.
* g++.dg/reflect/u8symbol_of1.C: New test.
* g++.dg/reflect/underlying_type1.C: New test.
* g++.dg/reflect/using1.C: New test.
* g++.dg/reflect/value_or_object1.C: New test.
* g++.dg/reflect/variable_of1.C: New test.
* g++.dg/reflect/variable_of2.C: New test.
* g++.dg/reflect/variable_of3.C: New test.
* g++.dg/reflect/variant1.C: New test.
* g++.dg/reflect/variant2.C: New test.
* g++.dg/reflect/vector1.C: New test.
* g++.dg/reflect/visibility1.C: New test.
Co-authored-by: Jakub Jelinek <jakub@redhat.com>
Signed-off-by: Valentyn Yukhymenko <vyuhimenko@bloomberg.net>
Signed-off-by: Alex Yesmanchyk <ayesmanchyk@bloomberg.net>
Signed-off-by: Michael Levine <mlevine55@bloomberg.net>
Reviewed-by: Jason Merrill <jason@redhat.com>
|
||
|
|
76ad28b112 |
libstdc++: Fix handling iterators with proxy subscript in heap algorithms.
This patch replaces uses of subscripts in heap algorithms, that where introduced in r16-4100-gaaeca77a79a9a8 with dereference of advanced iterators. The Cpp17RandomAccessIterator requirements, allows operator[] to return any type that is convertible to reference, however user-provided comparators are required only to accept result of dereferencing the iterator (i.e. reference directly). This is visible, when comparator defines operator() for which template arguments can be deduduced from reference (which will fail on proxy) or that accepts types convertible from reference (see included tests). For test we introduce a new proxy_random_access_iterator_wrapper iterator in testsuite_iterators.h, that returns a proxy type from subscript operator. This is separate type (instead of additional template argument and aliases), as it used for test that work with C++98. libstdc++-v3/ChangeLog: * include/bits/stl_heap.h (std::__is_heap_until, std::__push_heap) (std::__adjust_heap): Replace subscript with dereference of advanced iterator. * testsuite/util/testsuite_iterators.h (__gnu_test::subscript_proxy) (__gnu_test::proxy_random_access_iterator_wrapper): Define. * testsuite/25_algorithms/sort_heap/check_proxy_brackets.cc: New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com> |
||
|
|
59bc37debf |
libstdc++: Improve comments on __wait_args::_M_setup_proxy_wait
libstdc++-v3/ChangeLog: * include/bits/atomic_wait.h (__wait_args): Improve comments. * src/c++20/atomic.cc (__wait_args::_M_setup_proxy_wait): Improve comment. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> |
||
|
|
2226b67bbe |
libstdc++: constexpr flat_map and flat_multimap
This patch makes flat_map and flat_multimap constexpr as part of P3372R3. libstdc++-v3/ChangeLog: * include/bits/version.def: Add FTM. * include/bits/version.h: Regenerate. * include/std/flat_map: Add constexpr. * testsuite/23_containers/flat_map/1.cc: Add constexpr test. * testsuite/23_containers/flat_multimap/1.cc: Add constexpr test. |
||
|
|
5f02ba9258 |
libstdc++: Fix proxy wait detection in atomic wait
A failed assertion was observed with std::atomic<bool>::wait when the loop in __atomic_wait_address is entered and calls _M_setup_wait a second time, after waking from __wait_impl. When the first call to _M_setup_wait makes a call to _M_setup_proxy_wait that function decides that a proxy wait is needed for an object of type bool, and it updates the _M_obj and _M_obj_size members to refer to the futex in the proxy state, instead of referring to the bool object itself. The next time _M_setup_wait is called it calls _M_setup_proxy_wait again but now it sees _M_obj_size == sizeof(futex) and so this time decides a proxy wait is *not* needed, and then fails the __glibcxx_assert(_M_obj == addr) check. The problem is that _M_setup_proxy_wait wasn't correctly handling the case where it's called a second time, after the decision to use a proxy wait has already been made. That can be fixed in _M_setup_proxy_wait by checking if _M_obj != addr, which implies that a proxy wait has already been set up by a previous call. In that case, _M_setup_proxy_wait should only update _M_old to the latest value of the proxy _M_ver. This change means that _M_setup_proxy_wait is safe to call repeatedly for a proxy wait, and will only update _M_wait_state, _M_obj, and _M_obj_size on the first call. On the second and subsequent calls, those variables are already correctly set for the proxy wait so don't need to be set again. For non-proxy waits, calling _M_setup_proxy_wait more than once is safe, but pessimizes performance. The caller shouldn't make a second call to _M_setup_proxy_wait because we don't need to check again if a proxy wait should be used (the answer won't change) and we don't need to load a value from the proxy _M_ver. However, it was difficult to detect the case of a non-proxy wait, because _M_setup_wait doesn't know if it's being called the first time (when _M_setup_proxy_wait is called to make the initial decision) or a subsequent time (in which case _M_obj == addr implies a non-proxy wait was already decided on). As a result, _M_setup_proxy_wait was being used every time to see if it's a proxy wait. We can resolve this by splitting the _M_setup_wait function into _M_setup_wait and _M_on_wake, where the former is only called once to do the initial setup and the latter is called after __wait_impl returns, to prepare to check the predicate and possibly wait again. The new _M_on_wake function can avoid unnecessary calls to _M_setup_proxy_wait by checking _M_obj == addr to identify a non-proxy wait. The three callers of _M_setup_wait are updated to use _M_on_wake instead of _M_setup_wait after waking from a waiting function. This change revealed a latent performance bug in __atomic_wait_address_for which was not passing __res to _M_setup_wait, so a new value was always loaded even when __res._M_has_val was true. By splitting _M_on_wake out of _M_setup_wait this problem became more obvious, because we no longer have _M_setup_wait doing two different jobs, depending on whether it was passed the optional third argument or not. libstdc++-v3/ChangeLog: * include/bits/atomic_timed_wait.h (__atomic_wait_address_until): Use _M_on_wake instead of _M_setup_wait after waking. (__atomic_wait_address_for): Likewise. * include/bits/atomic_wait.h (__atomic_wait_address): Likewise. (__wait_args::_M_setup_wait): Remove third parameter and move code to update _M_old to ... (__wait_args::_M_on_wake): New member function to update _M_old after waking, only calling _M_setup_proxy_wait if needed. (__wait_args::_M_store): New member function to update _M_old from a value, for non-proxy waits. * src/c++20/atomic.cc (__wait_args::_M_setup_proxy_wait): If _M_obj is not addr, only load a new value and return true. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> |
||
|
|
9eb863f152 |
libstdc++: Ensure counting_semaphore::try_acquire_for times out [PR122878]
As noted in Bug 122878 comment 2, the _M_try_acquire_for implementation doesn't reduce the remaining timeout each time it returns from an atomic waiting function. This means that it can wait longer than requested, or even loop forever. If there is a spurious wake from the timed waiting function (__wait_until_impl) it will return indicating no timeout occurred, which means the caller will check the value and potentially sleep again. If spurious wakes happen every time, it will just keep sleeping in a loop forever. This is observed to actually happen on FreeBSD 14.0-STABLE where pthread_cond_timedwait gets a spurious wake and so never times out. The solution in this commit is to replace the implementation of _M_try_acquire_for with a call to _M_try_acquire_until, converting the relative timeout to an absolute timeout against the steady clock. This is what ends up happening anyway, because we only have a __wait_until_impl entry point into the library internals, so __atomic_wait_address_for already converts the relative timeout to an absolute timeout (except for the special case of a zero-value duration, which only checks for an update while spinning for a finite number of iterations, and doesn't sleep). As noted in comment 4 of the PR, this requires some changes to _M_try_acquire which was relying on the behaviour of _M_try_acquire_for for zero-value durations. That behaviour is desirable for _M_try_acquire so that it can handle short-lived contention without failing immediately. To preserve that behaviour of _M_try_acquire it is changed to do its own loop and to call __atomic_wait_address_for directly with a zero duration, to do the spinloop. libstdc++-v3/ChangeLog: PR libstdc++/122878 * include/bits/semaphore_base.h (_M_try_acquire): Replace _M_try_acquire_for call with explicit loop and call to __atomic_wait_address_for. (_M_try_acquire_for): Replace loop with call to _M_try_acquire_until. Co-authored-by: Tomasz Kamiński <tkaminsk@redhat.com> |
||
|
|
a94bd31fd8 |
libstdc++: Fix std::basic_stringbuf::str()&& [PR123100]
When basic_stringbuf::setbuf has been called we need to copy the contents of the buffer into _M_string first, before returning that. libstdc++-v3/ChangeLog: PR libstdc++/123100 * include/std/sstream (basic_stringbuf::str()&&): Handle the case where _M_string is not being used for the buffer. * testsuite/27_io/basic_stringbuf/str/char/123100.cc: New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> |