mirror of
https://github.com/gcc-mirror/gcc.git
synced 2026-05-06 23:25:24 +02:00
59bc37debfbf315a7cd0c8bbbfcecdf87b6ea91a
128 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
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. |
||
|
|
254a858ae7 | Update copyright years. | ||
|
|
278eb0a081 |
libstdc++: Make __cpp_lib_constexpr_exceptions depend on cxx11 ABI
The COW std::string is not constexpr, so the <stdexcept> exception classes can't be constexpr either when they're defined in terms of the COW string. While constexpr exceptions for <typeinfo>, <new>, and <exception> classes would work, __cpp_constexpr_exceptions >= 202411L implies that everything including <stdexcept> should work. So when we can't support it fully, we shouldn't announce it. libstdc++-v3/ChangeLog: * include/bits/version.def (constexpr_exceptions): Add cxx11abi=yes. * include/bits/version.h: Regenerate. * testsuite/18_support/exception/version.cc: Require effectiove target cxx11_abi. * testsuite/18_support/exception_ptr/exception_ptr_cast.cc: Only check for constexpr support in cxx11 ABI. * testsuite/19_diagnostics/headers/stdexcept/version.cc: Require effective target cxx11_abi. * testsuite/19_diagnostics/logic_error/constexpr.cc: Likewise. * testsuite/19_diagnostics/runtime_error/constexpr.cc: Likewise. * testsuite/20_util/expected/version.cc: Only check for __cpp_lib_constexpr_exceptions macro for cxx11 ABI. * testsuite/20_util/optional/version.cc: Likewise. * testsuite/20_util/variant/version.cc: Likewise. Reviewed-by: Jakub Jelinek <jakub@redhat.com> |
||
|
|
12084561db |
libstdc++: Implement std::philox_engine for targets without __int128
This moves the __detail::_Select_uint_least_t<N>::type class to namespace scope and extends it with more 128-bit arithmetic operations, implemented in terms of uint64_t. Now std::philox_engine can use _Select_uint_least_t<w*2>::type instead of __uint128_t, so that it works on targets without 128-bit integers. This also means that targets that do support __uint128_t only use it when actually necessary, so that we use uint64_t when generating a 32-bit result (e.g. with std::philox4x32). libstdc++-v3/ChangeLog: * include/bits/random.h [!__SIZEOF_INT128__] (__rand_uint128): Refactor and rename _Select_uint_least_t<128>::type to a new class. Make all members constexpr. Add new member functions for additional arithmetic and bitwise operations, and comparisons. (__detail::_Select_uint_least_t<>::type): Define as an alias of __rand_uint128. * include/bits/random.tcc (philox_engine::_M_mulhi): Use _Select_uint_least_t<w*2>::type instead of __uint128_t. (philox_engine::_M_transition): Likewise. * include/bits/version.def (philox_engine): Remove extra_cond. * include/bits/version.h: Regenerate. * testsuite/26_numerics/random/philox4x32.cc: Remove dg-require-cpp-feature-test directive. * testsuite/26_numerics/random/philox4x64.cc: Likewise. * testsuite/26_numerics/random/philox_engine/cons/copy.cc: Likewise. * testsuite/26_numerics/random/philox_engine/cons/default.cc: Likewise. * testsuite/26_numerics/random/philox_engine/cons/seed.cc: Likewise. * testsuite/26_numerics/random/philox_engine/operators/equal.cc: Likewise. * testsuite/26_numerics/random/philox_engine/operators/serialize.cc: Likewise. * testsuite/26_numerics/random/philox_engine/requirements/constants.cc: Likewise. * testsuite/26_numerics/random/philox_engine/requirements/typedefs.cc: Likewise. Co-authored-by: Jakub Jelinek <jakub@redhat.com> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> |
||
|
|
1d29b68562 |
libstdc++: Implement P2408R5 C++20 iterators as inputs to STL algos
From the paper's abstract: Change the iterator requirements for non-Ranges algorithms. For forward iterators and above that are constant iterators, instead of requiring that iterators meet certain Cpp17...Iterator requirements, require that the iterators model certain iterator concepts. This makes iterators from several standard views usable with non-Ranges algorithms that require forward iterators or above, such as the parallel overloads of most algorithms. This patch narrowly implements P2408R5 in C++23 mode and C++20 mode (as an extension). "Narrowly" because just as in the paper, we don't attempt to relax the requirements of mutable iterators even though it's possible in theory. Note that the PSTL algorithm requirements have already been relaxed in r15-3650. And we don't bother touching the deprecated parallel mode algorithms under ./include/parallel. The main workhorse of this paper is a new helper __iterator_concept_or_category that replaces eligible uses of __iterator_category and iterator_traits::iterator_category. This new helper considers both the iterator_concept and iterator_category of the given iterator and returns the former if it's at least as strong as the latter. It's implemented in terms of the __promotable_iterator concept added in r16-2588 that made std::advance etc aware of C++20 iterators. Note that this helper doesn't check the actual C++20 iterator concepts (which check syntactic requirements along with iterator_concept if it's defined) and instead just checks for, and fully trusts, the iterator_concept defined by the iterator type. This is a slight deviation from the paper but IMHO it's consistent with the existing trusting of iterator_category and should be good enough in practice, though it means C++20 iterators that don't define iterator_concept will not be recognized as such by this helper even if they otherwise model the std::foo_iterator concept. (An undefined iterator_concept effectively defaults to random_access_iterator_tag.) Most of the changes made here are effectively optimizations that don't have a semantic impact, e.g. for std::reduce. I added tests for a couple of algorithms where these changes are observable. The new __iterator_concept_or_category helper can probably also be used to fix PR100070 "Standard library container iterator-pair constructors should check C++20 iterator concepts". As a follow-up to this patch we should either remove the Boost-style concept checks, or relax them accordingly. It seems we're leaning towards removing them outright; see this thread: https://gcc.gnu.org/pipermail/libstdc++/2025-May/061568.html As suggested by Tomasz, this patch also introduces a _GLIBCXX_ITER_MOVE wrapper around ranges::iter_move that also converts to the iterator's value type (and is usable before C++20 as well). PR libstdc++/113299 libstdc++-v3/ChangeLog: * include/bits/deque.tcc (__copy_move_a1): Constrain with __is_any_random_access_iter instead of __is_random_access_iter. (__copy_move_backward_a1): Likewise. (__equal_aux1): Likewise. * include/bits/stl_algo.h (__search_n): Use __iter_concept_or_category instead of __iterator_category or iterator_traits::iterator_category. (find_end): Likewise. (__is_permutation): Likewise. (for_each_n): Likewise. (unique_copy): Likewise, for constant iterators. (sample): Likewise, for constant iterators. * include/bits/stl_algobase.h (__copy_move_a1): Adjust deque-based forward declaration accordingly. (__copy_move_backward_a1): Likewise. (__equal_aux1): Likewise. (__lexicographical_compare_impl): Use __iter_concept_or_category instead of __iterator_category or iterator_traits::iterator_category. (__equal4): Likewise. * include/bits/stl_iterator_base_funcs.h (__iter_concept_or_category): New. (__is_any_random_access_iter): New. (_GLIBCXX_ITER_MOVE): New. * include/bits/stl_uninitialized.h (uninitialized_copy_n): Use __iterator_concept_or_category instead of __iterator_category for the constant iterator __first. (__uninitialized_copy_n_pair): Likewise. * include/bits/version.def (algorithm_iterator_requirements): Define. * include/bits/version.h: Regenerate. * include/std/algorithm: Provide the FTM __cpp_lib_algorithm_iterator_requirements. * include/std/memory: Likewise. * include/std/numeric: Likewise. Include <bits/stl_iterator_base_funcs.h>. (reduce): Use __is_any_random_access_iter instead of __is_random_access_iter. (transform_reduce): Likewise. (inclusive_scan): Use _GLIBCXX_ITER_MOVE instead of std::move. * testsuite/25_algorithms/find_end/c++20_iter.cc: New test. * testsuite/25_algorithms/sample/c++20_iter.cc: New test. * testsuite/25_algorithms/search_n/c++20_iter.cc: New test. * testsuite/25_algorithms/unique_copy/c++20_iter.cc: New test. * testsuite/26_numerics/inclusive_scan/c++20_iter.cc: New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com> |
||
|
|
62c126db6b |
libstdc++: Implement C++26 P3378R2 - constexpr exception types
The following patch attempts to implement the C++26 P3378R2 - constexpr exception types paper. This is quite complicated, because most of these classes which should be constexpr-ized use solely or mostly out of line definitions in libstdc++, both for historical, code size and dual ABI reasons, so that one can throw these as exceptions between TUs with old vs. new (or vice versa) ABIs. For this reason, logic_error/runtime_error and classes derived from it have the old ABI std::string object inside of them and the exported APIs from libstdc++.so.6 ensure the right thing. Now, because new invoked during constant evaluation needs to be deleted during the same constant evaluation and can't leak into the constant expressions, I think we don't have to use COW strings under the hood (which aren't constexpr I guess because of reference counting/COW) and we can use something else, the patch uses heap allocated std::string object (where __cow_constexpr_string class has just a pointer to that). As I think we still want to hide the ugly details if !consteval in the library, the patch exports 8 __cow_string class symbols (6 existing which were previously just not exported and 2 new ones) and if !consteval calls those through extern "C" _Zmangled_name symbols. The functions are always_inline. And then logic_error etc. have for C++26 (precisely for __cpp_lib_constexpr_exceptions >= 202502L) constexpr definitions of cdtors/methods. This results in slightly larger code (a few insns at most) at runtime for C++26, e.g. instead of calling say some logic error cdtor/method with 2 arguments it calls some __cow_string one with 2 arguments but + 8 bytes pointer additions on both. The patch also removes the __throw_format_error forward declaration which apparently wasn't needed for anything as all __throw_format_error users were either in <format> or included <format> before the uses, reverts the https://gcc.gnu.org/pipermail/libstdc++/2025-July/062598.html patch and makes sure __throw_* functions (only those for exception types which the P3378R2 or P3068R5 papers made constexpr usable and there are actually constexpr/consteval uses of those) are constexpr for C++26 constexpr exceptions. The patch does that by splitting the bits/functexcept.h header: 1) bits/functexcept.h stays for the __throw_* functions which are (at least for now) never constexpr (the <ios>, <system_error>, <future> and <functional> std::exception derived classes) or are never used or never used in constexpr/consteval contexts (<exception>, <typeinfo> std::exception derived classes and std::range_error). 2) bits/new_{throw,except}.h for __throw_bad_alloc/__throw_bad_array_new_length and std::bad_alloc/std::bad_array_new_length (where <new> includes <bits/new_except.h> and <bits/new_throw.h> as well for the C++26 constexpr exceptions case) 3) for the most complicated <stdexcept> stuff, one header addition to bits/stdexcept.h one header for the __throw_logic_error etc. forward declarations, one header for the __throw_logic_error etc. definitions and one header without header guards which will depending on __glibcxx_exc_in_string include one or the other because <string> vs. <string_view> vs. <stdexcept> have heavy interdependencies 2025-12-11 Jakub Jelinek <jakub@redhat.com> PR libstdc++/121114 libstdc++-v3/ * include/bits/version.def: Implement C++26 P3378R2 - constexpr exception types. (constexpr_exceptions): Change value from 1 to 202502, remove no_stdname and TODO comments. * include/bits/version.h: Regenerate. * src/c++11/cow-stdexcept.cc (__cow_string(const char*)): New ctor. (__cow_string::c_str()): New method. * config/abi/pre/gnu.ver (GLIBCXX_3.4.35): Export 8 __cow_string symbols. * include/bits/new_except.h: New file. * include/bits/new_throw.h: New file. * include/bits/stdexcept_throw.h: New file. * include/bits/stdexcept_throwdef.h: New file. * include/bits/stdexcept_throwfwd.h: New file. * include/std/stdexcept: Include bits/stdexcept_except.h and move everything after <string> include except for std::range_error into include/bits/stdexcept_except.h. (std::range_error): If __cpp_lib_constexpr_exceptions >= 202502L make all cdtors and methods constexpr. * include/bits/stdexcept_except.h: New file. * include/std/optional (__glibcxx_want_constexpr_exceptions): Define before including bits/version.h. (bad_optional_access::what): Make constexpr for __cpp_lib_constexpr_exceptions >= 202502L. (__throw_bad_optional_access): Likewise. * include/std/expected (__glibcxx_want_constexpr_exceptions): Define before including bits/version.h. (bad_expected_access): Make cdtors and all methods constexpr for __cpp_lib_constexpr_exceptions >= 202502L. * include/std/format (__glibcxx_want_constexpr_exceptions): Define before including bits/version.h. (_GLIBCXX_CONSTEXPR_FORMAT_ERROR): Define and undef later. (format_error): Use _GLIBCXX_CONSTEXPR_FORMAT_ERROR on ctors. * include/std/variant (__glibcxx_want_constexpr_exceptions): Define before including bits/version.h. (_GLIBCXX_CONSTEXPR_BAD_VARIANT_ACCESS): Define and undef later. (bad_variant_access): Use it on ctors and what() method. (__throw_bad_variant_access): Use it here too. * testsuite/18_support/exception/version.cc: Adjust expected __cpp_lib_constexpr_exceptions value. * testsuite/19_diagnostics/runtime_error/constexpr.cc: New test. * testsuite/19_diagnostics/headers/stdexcept/version.cc: New test. * testsuite/19_diagnostics/logic_error/constexpr.cc: New test. * testsuite/20_util/expected/observers.cc (test_value_throw): Change return type to bool from void, return true at the end, add test to dereference what() first character. Make it constexpr for __cpp_lib_constexpr_exceptions >= 202502L and add static_assert. * testsuite/20_util/expected/version.cc: Add tests for __cpp_lib_constexpr_exceptions value. * testsuite/20_util/variant/constexpr.cc: For __cpp_lib_constexpr_exceptions >= 202502L include <string>. (test_get): New function if __cpp_lib_constexpr_exceptions >= 202502L, assert calling it is true. * testsuite/20_util/variant/version.cc: Add tests for __cpp_lib_constexpr_exceptions value. * testsuite/20_util/optional/constexpr/observers/3.cc: Include testsuite_hooks.h. (eat, test01): New functions. Assert test01() is true. * testsuite/20_util/optional/version.cc: Add tests for __cpp_lib_constexpr_exceptions value. * include/std/future: Add #include <bits/functexcept.h>. * include/std/shared_mutex: Include <bits/new_throw.h>. * include/std/flat_map: Include <bits/stdexcept_throw.h> instead of <bits/functexcept.h>. * include/std/syncstream: Remove <bits/functexcept.h> include. * include/std/flat_set: Likewise. * include/std/bitset: Include <bits/stdexcept_throw.h> instead of <bits/functexcept.h>. * include/std/string_view: Don't include <bits/functexcept.h>, include <bits/stdexcept_throw.h> early if __glibcxx_exc_in_string is not defined and include <bits/stdexcept_throw.h> at the end of the header again if __glibcxx_exc_in_string is 2 and C++26 constexpr exceptions are enabled. (__glibcxx_exc_in_string): Define if __glibcxx_exc_in_string wasn't defined before including <bits/stdexcept_throw.h>. * include/std/array: Include <bits/stdexcept_throw.h> instead of <bits/functexcept.h>. * include/std/inplace_vector: Likewise. * include/std/string: Include <bits/stdexcept_except.h> and <bits/stdexcept_throw.h> after bits/basic_string.tcc include if C++26 constexpr exceptions are enabled and include <bits/stdexcept_throw.h> instead of <bits/functexcept.h> early. (__glibcxx_exc_in_string): Define early to 1, undefine at the end. * include/std/deque: Include <bits/stdexcept_throw.h>. * include/bits/new_allocator.h: Include <bits/new_throw.h> instead of <bits/functexcept.h>. * include/bits/stl_algobase.h: Remove <bits/functexcept.h> include. * include/bits/stl_vector.h: Include <bits/stdexcept_throw.h> instead of <bits/functexcept.h>. * include/bits/memory_resource.h: Include <bits/new_throw.h> instead of <bits/functexcept.h>. * include/bits/functexcept.h: Guard everything after includes with #if _GLIBCXX_HOSTED. (__throw_bad_alloc, __throw_bad_array_new_length, __throw_logic_error, __throw_domain_error, __throw_invalid_argument, __throw_length_error, __throw_out_of_range, __throw_out_of_range_fmt, __throw_runtime_error, __throw_overflow_error, __throw_underflow_error): Move declarations to other headers - <bits/new_throw.h> and <bits/stdexcept_throwfwd.h>. * include/bits/stl_map.h: Include <bits/stdexcept_throw.h> instead of <bits/functexcept.h>. * include/bits/hashtable_policy.h: Include <bits/stdexcept_throw.h> instead of <bits/functexcept.h>. * include/bits/formatfwd.h (std::__throw_format_error): Remove declaration. * include/bits/specfun.h: Include <bits/stdexcept_throw.h> instead of <bits/functexcept.h>. * include/bits/basic_ios.h: Include <bits/functexcept.h>. * include/bits/locale_classes.h: Likewise. * include/tr1/cmath: Include <bits/stdexcept_throw.h> instead of <bits/functexcept.h>. * include/tr1/memory: Remove <bits/functexcept.h> include. * include/tr1/array: Include <bits/stdexcept_throw.h>. * include/ext/vstring_util.h: Include <bits/stdexcept_throw.h> instead of <bits/functexcept.h>. * include/ext/bitmap_allocator.h: Include <bits/new_throw.h> instead of <bits/functexcept.h>. * include/ext/mt_allocator.h: Likewise. * include/ext/malloc_allocator.h: Likewise. * include/ext/debug_allocator.h: Include <bits/stdexcept_throw.h> instead of <bits/functexcept.h>. * include/ext/concurrence.h: Include <bits/exception_defines.h> instead of <bits/functexcept.h>. * include/ext/throw_allocator.h: Include <bits/new_throw.h> and <bits/stdexcept_throw.h> instead of <bits/functexcept.h>. * include/ext/string_conversions.h: Include <bits/stdexcept_throw.h> instead of <bits/functexcept.h>. * include/ext/pool_allocator.h: Include <bits/new_throw.h> instead of <bits/functexcept.h>. * include/ext/ropeimpl.h: Include <bits/stdexcept_throw.h> instead of <bits/functexcept.h>. * include/tr2/dynamic_bitset: Likewise. * include/experimental/optional: Include <bits/exception_defines.h> instead of <bits/functexcept.h>. * include/Makefile.am (bits_freestanding): Add ${bits_srcdir}/{new,stdexcept}_{except,throw}.h and ${bits_srcdir}/stdexcept_throw{fwd,def}.h. * include/Makefile.in: Regenerate. * src/c++17/floating_from_chars.cc: Remove <bits/functexcept.h> include. * src/c++11/regex.cc: Likewise. * src/c++11/functexcept.cc: Likewise. * src/c++11/snprintf_lite.cc: Include <bits/stdexcept_throw.h> instead of <bits/functexcept.h>. * src/c++11/thread.cc: Include <bits/functexcept.h>. * testsuite/util/testsuite_hooks.h: Include <bits/stdexcept_throw.h> instead of <bits/functexcept.h>. * testsuite/util/io/verified_cmd_line_input.cc: Include <bits/exception_defines.h> instead of <bits/functexcept.h>. * testsuite/20_util/allocator/105975.cc: Expect different diagnostics for C++26. * testsuite/23_containers/inplace_vector/access/capacity.cc: Remove #error, guard if consteval { return; } with #ifndef __cpp_lib_constexpr_exceptions. * testsuite/23_containers/inplace_vector/access/elem.cc: Likewise. * testsuite/23_containers/inplace_vector/cons/1.cc: Likewise. * testsuite/23_containers/inplace_vector/cons/from_range.cc: Likewise. * testsuite/23_containers/inplace_vector/modifiers/single_insert.cc: Likewise. * testsuite/23_containers/inplace_vector/modifiers/assign.cc: Likewise. * testsuite/23_containers/inplace_vector/modifiers/multi_insert.cc: Likewise. * libsupc++/new: Include <bits/new_except.h>. (std::bad_alloc, std::bad_array_new_length): Move defintion to <bits/new_except.h>. libgomp/ * omp.h.in: Include <bits/new_throw.h> instead of <bits/functexcept.h>. gcc/testsuite/ * g++.dg/tree-ssa/pr110819.C: Guard scan-tree-dump-not delete on c++23_down and add comment explaining why C++26 fails that. * g++.dg/tree-ssa/pr96945.C: Likewise. * g++.dg/tree-ssa/pr109442.C: Likewise. * g++.dg/tree-ssa/pr116868.C: Likewise. * g++.dg/tree-ssa/pr58483.C: Likewise. |
||
|
|
bf9dd44a97 |
libstdc++: constexpr flat_set and flat_multiset
This patch makes flat_set and flat_multiset constexpr as part of P3372R3. libstdc++-v3/ChangeLog: * include/bits/version.def: Add FTM. * include/bits/version.h: Regenerate. * include/std/flat_set: Add constexpr. * testsuite/23_containers/flat_multiset/1.cc: Add constexpr test. * testsuite/23_containers/flat_set/1.cc: Add constexpr test. |
||
|
|
1dd44ebd5f |
libstdc++: Regenerate <bits/version.h>
Some pre-r16-4328-g71e95e871d62e4 comments sneaked back in with some recent commits. libstdc++-v3/ChangeLog: * include/bits/version.h: Regenerate. |
||
|
|
e2026d74f6 |
libstdc++: Set __cpp_lib_submdspan to 202411.
The submdspan feature is complete and this commit sets the feature testing macros accordingly. Also makes the feature testing macro submdspan depend on constant_wrapper. Also changes the value of the internal feature testing macro for padded layouts to 202403. libstdc++-v3/ChangeLog: * include/bits/version.def (padded_layouts): Set to 202403. (submdspan): Set to 202411 add dependency. * include/bits/version.h: Regenerate. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com> |
||
|
|
03562c1e02 |
libstdc++: Implement P2404R3 relaxations to comparable_with concepts [PR122946]
This implements the C++23 proposal P2404R3 "Move-only types for equality_comparable_with, totally_ordered_with, and three_way_comparable_with". As agreed with the maintainers of libc++ and MSVC STL, we treat this as a DR for C++20. It allows reasonable code to compile which wasn't originally allowed in C++20, and only affects some obscure subsumption cases for valid C++20 code. libstdc++-v3/ChangeLog: PR libstdc++/122946 * include/bits/version.def (concepts): Set value to 202207. * include/bits/version.h: Regenerate. * include/std/concepts (__comparison_common_type_with_impl) (__comparison_common_type_with): New helper concepts. (equality_comparable_with): Use __comparison_common_type_with. * libsupc++/compare (three_way_comparable_with): Likewise. (__glibcxx_want_concepts): Define to get __cpp_lib_concepts here. * testsuite/std/concepts/concepts.compare/move_only.cc: New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> |
||
|
|
d1ac432c5a |
libstdc++: Implement rest of P2655R3 common_reference of reference_wrapper
PR libstdc++/120446 libstdc++-v3/ChangeLog: * include/bits/refwrap.h (__detail::__is_ref_wrapper): Define as per P2655R3 for C++20. (__detail::__ref_wrap_common_reference_exists_with): Likewise. (basic_common_reference): Define partial specializations using the above as per P2655R3 for C++20. * include/bits/version.def (common_reference_wrapper): New. * include/bits/version.h: Regenerate. * include/std/functional (__glibcxx_want_common_reference_wrapper): Define. * testsuite/20_util/reference_wrapper/p2655r3.cc: New test. Co-authored-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com> |
||
|
|
a9fd651fbb |
libstdc++: Implement P2655R3 changes to common_reference bullet 1
We implement this paper as a DR against C++20 (as do MSVC and libc++). PR libstdc++/120446 libstdc++-v3/ChangeLog: * include/bits/version.def (common_reference): New. * include/bits/version.h: Regenerate. * include/std/type_traits (__glibcxx_want_common_reference): Define. (__common_reference_impl<T1, T2, 1>): Add pointer convertibility constraints as per P2655R3. * testsuite/20_util/common_reference/p2655r3.cc: New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com> |
||
|
|
475933164f |
libstdc++: implement P3044R2 - sub-string_view from string (string_view part)
libstdc++-v3/ChangeLog: * include/bits/version.def: Add string_subview FTM. * include/bits/version.h: Regenerate. * include/std/string_view: Add subview. * testsuite/21_strings/basic_string_view/operations/subview/char.cc: New test. * testsuite/21_strings/basic_string_view/operations/subview/wchar_t.cc: New test. |
||
|
|
1c9d93bfcd |
libstdc++: Hashing support for chrono value classes [PR110357]
This patch implements P2592R3 Hashing support for std::chrono value classes. To avoid the know issues with current hashing of integer types (see PR104945), we use chrono::__int_hash function that hash the bytes of representation, instead of hash<T>, as the later simply cast to value. Currently _Hash_impl it used, but we should consider replacing it (see PR55815) before C++26 ABI is made stable. The function is declared inside <chrono> header and chrono namespace, to make sure that only chrono components would be affected by such change. Finally, chrono::__int_hash is made variadic, to support combining hashes of multiple integers. To reduce the number of calls to hasher (defined out of line), the calendar types are packed into single unsigned integer value. This is done by chrono::__hash helper, that calls: * chrono::__as_int to cast the value of single component, to unsigned integer with size matching the one used by internal representation: unsigned short for year/weekday_indexed, and unsigned char in all other cases, * chrono::__pack_ints to pack integers (if more than one) into single integer by performing bit shift operations, * chrono::__int_hash to hash the value produced by above. Hashing of duration, time_point, and zoned_time only hashes the value and ignores any difference in the period, i.e. hashes of nanoseconds(2) and seconds(2) are the same. This does not affect the usages inside unordered containers, as the arguments are converted to key type first. To address that period::num and period::den could be included in the hash, however such approach will not make hashes of equal durations (2000ms, 2s) equal, so they would remain unusable for precomputed hashes. In consequence, including period in hash, would only increase runtime cost, withou any clear benefits. Futhermore, chrono::__int_hash is used when the duration representation is integral type, and for other types (floating point due special handling of +/-0.0 and user defined types) we delegate to hash specialization. This is automatically picked up by time_point, that delegates to hasher of duration. Similarly for leap_second that is specified to use integer durations, we simply hash representations of date() and value(). Finally zoned_time in addition to handling integer durations as described above, we also use __int_hash for const time_zone* (if used), as hash<T*> have similar problems as hash specialization for integers. This is limited only to _TimeZonePtr being const time_zone* (default), as user can define hash specializations for raw pointers to they zones. As accessing the representation for duration requires calling count() method that returns a copy of representation by value, the noexcept specification of the hasher needs to take into consideration copy constructor of duration. Similar reasoning applies for time_since_epoch for time_points, and get_sys_time, get_time_zone for zoned_time. For all this cases we use internal __is_nothrow_copy_hashable concept. Finally support for zoned_time is provided only for CXX11 string ABI, __cpp_lib_chrono feature test macro cannot be bumped if COW string are used. To indicate presence of hasher for remaining types this patch also bumps the internal __glibcxx_chrono_cxx20 macro, and uses it as guard to new features. PR libstdc++/110357 libstdc++-v3/ChangeLog: * include/bits/version.def (chrono, chrono_cxx20): Bump values. * include/bits/version.h: Regenerate. * include/std/chrono (__is_nothrow_copy_hashable) (chrono::__pack_ints, chrono::__as_int, chrono::__int_hash) (chrono::__hash): Define. (std::hash): Define partial specialization for duration, time_point, and zoned_time, and full specializations for calendar types and leap_second. (std::__is_fast_hash): Define partial specializations for duration, time_point, zoned_time. * testsuite/std/time/hash.cc: New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Co-authored-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> |
||
|
|
acdf675933 |
libstd++: Implement C++23 P2674R1 - A trait for implicit lifetime types
The following patch attempts to implement the library side of the C++23 P2674R1 paper. As mentioned in the paper, since CWG2605 the trait isn't really implementable purely on the library side. The compiler side has been committed earlier, so this just uses the new builtin trait on the library side. 2025-10-30 Jakub Jelinek <jakub@redhat.com> * include/bits/version.def (is_implicit_lifetime): New. * include/bits/version.h: Regenerate. * include/std/type_traits (std::is_implicit_lifetime, std::is_implicit_lifetime_v): New trait. * src/c++23/std.cc.in (std::is_implicit_lifetime, std::is_implicit_lifetime_v): Export. * testsuite/20_util/is_implicit_lifetime/version.cc: New test. * testsuite/20_util/is_implicit_lifetime/value.cc: New test. |
||
|
|
23657d3972 |
libstdc++: Implement optional<T&> from P2988R12 [PR121748]
This patch implements optional<T&> based on the P2988R12 paper, incorporating
corrections from LWG4300, LWG4304, and LWG3467. The resolution for LWG4015
is also extended to cover optional<T&>.
We introduce _M_fwd() helper, that is equivalent to operator*(), except that
it does not check non-empty precondition. It is used in to correctly propagate
the value during move construction from optional<T&>. This is necessary because
moving an optional<T&> must not move the contained object, which is the key
distinction between *std::move(opt) and std::move(*opt).
The implementation deviates from the standard by providing a separate std::swap
overload for std::optional<T&>, which simplifies preserving the resolution of
LWG2766.
This introduces a few changes to make_optional behavior (see included test):
* some previously valid uses of make_optional<T>({...}) (where T is not a
reference type) now become ill-formed (see optional/make_optional_neg.cc).
* make_optional<T&>(t) and make_optional<const T&>(ct), where decltype(t) is T&,
and decltype(ct) is const T& now produce optional<T&> and optional<const T&>
respectively, instead of optional<T>.
* a few other uses of make_optional<R> with reference type R are now ill-formed.
PR libstdc++/121748
libstdc++-v3/ChangeLog:
* include/bits/version.def: Bump value for optional,
* include/bits/version.h: Regenerate.
* include/std/optional (std::__is_valid_contained_type_for_optional):
Define.
(std::optional<T>): Use __is_valid_contained_type_for_optional.
(optional<T>(const optional<_Up>&), optional<T>(optional<_Up>&&))
(optional<T>::operator=(const optional<_Up>&))
(optional<T>::operator=(optional<_Up>&&)): Replacex._M_get() with
x._M_fwd(), and std::move(x._M_get()) with std::move(x)._M_fwd().
(optional<T>::and_then): Remove uncessary remove_cvref_t.
(optional<T>::_M_fwd): Define.
(std::optional<T&>): Define new partial specialization.
(std::swap(std::optional<T&>, std::optional<T&>)): Define.
(std::make_optional(_Tp&&)): Add non-type template parameter.
(std::make_optional): Use parenthesis to constructor optional.
(std::hash<optional<T>>): Add comment.
* testsuite/20_util/optional/make_optional-2.cc: Guarded not longer
working example.
* testsuite/20_util/optional/relops/constrained.cc: Expand test to
cover optionals of reference.
* testsuite/20_util/optional/requirements.cc: Ammend for
optional<T&>.
* testsuite/20_util/optional/requirements_neg.cc: Likewise.
* testsuite/20_util/optional/version.cc: Test new value of
__cpp_lib_optional.
* testsuite/20_util/optional/make_optional_neg.cc: New test.
* testsuite/20_util/optional/monadic/ref_neg.cc: New test.
* testsuite/20_util/optional/ref/access.cc: New test.
* testsuite/20_util/optional/ref/assign.cc: New test.
* testsuite/20_util/optional/ref/cons.cc: New test.
* testsuite/20_util/optional/ref/internal_traits.cc: New test.
* testsuite/20_util/optional/ref/make_optional/1.cc: New test.
* testsuite/20_util/optional/ref/make_optional/from_args_neg.cc:
New test.
* testsuite/20_util/optional/ref/make_optional/from_lvalue_neg.cc:
New test.
* testsuite/20_util/optional/ref/make_optional/from_rvalue_neg.cc:
New test.
* testsuite/20_util/optional/ref/monadic.cc: New test.
* testsuite/20_util/optional/ref/relops.cc: New test.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Co-authored-by: Tomasz Kamiński <tkaminsk@redhat.com>
|
||
|
|
7aefb48bb0 |
libstdc++: Implement P3060R3: Add std::views::indices(n)
This patch adds the views::indices function using iota. libstdc++-v3/ChangeLog: * include/bits/version.def: Add ranges_indices FTM. * include/bits/version.h: Regenerate. * include/std/ranges: Implement views::indices. * testsuite/std/ranges/indices/1.cc: New test. |
||
|
|
1e84849cb2 |
libstdc++: Implement P1494 and P3641 Partial program correctness [PR119060]
This implements the library parts of P1494 as amended by P3641. For GCC the compiler itself treats stdio operations as equivalent to the observable checkpoint and thus it does not appear to be necessary to add calls to those functions (it will not alter the outcome). This adds the facility for C++26, although there is no reason, in principle, that it would not work back to C++11 at least. PR c++/119060 libstdc++-v3/ChangeLog: * include/bits/version.def: Add observable_checkpoint at present allowed from C++26. * include/bits/version.h: Regenerate. * include/std/utility: Add std::observable_checkpoint(). * src/c++23/std.cc.in: Add obervable_checkpoint () to utility. Signed-off-by: Iain Sandoe <iain@sandoe.co.uk> |
||
|
|
1c5e1093a7 |
libstdc++: Implement P2835R7 Expose std::atomic_ref's object address
This patch adds the address function to __atomic_ref_base. libstdc++-v3/ChangeLog: * include/bits/atomic_base.h: Implement address(). * include/bits/version.def: Bump version number. * include/bits/version.h: Regenerate. * testsuite/29_atomics/atomic_ref/address.cc: New test. |
||
|
|
c8b388a948 |
libstdc++: Implement P3235R3 optimizations for std::print [PR121790]
This patch implements additional enable_nonlocking_formatter_optimization specializations listed in P3235R3. PR libstdc++/121790 libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (enable_nonlocking_formatter_optimization): Define specializations for chrono types. * include/bits/version.def (print): Bump. * include/bits/version.h: Regenerate. * include/std/format (enable_nonlocking_formatter_optimization): Define specializations for pair, tuple and ranges. * include/std/queue (enable_nonlocking_formatter_optimization): Define specializations for queue and priority_queue. * include/std/stack (enable_nonlocking_formatter_optimization): Define specialization for stack. * include/std/stacktrace (enable_nonlocking_formatter_optimization): Define specialization for basic_stacktrace and stacktrace_entry. * include/std/thread (enable_nonlocking_formatter_optimization): Define specialization for thread::id. * include/std/vector (enable_nonlocking_formatter_optimization): Define specialization for vector<bool>::reference. * testsuite/23_containers/vector/bool/format.cc: Test value of enable_nonlocking_formatter_optimization. * testsuite/30_threads/thread/id/output.cc: Likewise. * testsuite/std/format/ranges/adaptors.cc: Likewise. * testsuite/std/format/ranges/formatter.cc: Likewise. * testsuite/std/format/tuple.cc: Likewise. * testsuite/std/time/format/empty_spec.cc: Extract Rep class to custom_rep.h. * testsuite/std/time/format/custom_rep.h: Extracted from empty_spec.cc. * testsuite/std/time/format/nonlocking.cc: New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> |
||
|
|
8bd872f1ea |
libstdc++: Implement P3107R5 optimizations for std::print [PR121790]
The names of the vprint functions follow the convention from P3235R3. This takes advantage of the additional permission proposed by P3107R5 so that std::print can write directly to a FILE stream, rather than formatting to an intermediate std::string temporary and then writing that to the stream. The change is to write to a new _File_sink type instead of a _Str_sink that populates a std::string. There are three implementations of _File_sink. For non-Glibc targets that support POSIX flockfile and putc_unlocked, the stream will be locked and then formatted characters will be buffered on the stack (instead of allocating a std::string) and copied to the stream when the buffer fills up. For Glibc, _File_sink will lock the stream but then if the file is line-buffered or fully buffered, characters will be written directly into the file's output buffer. This avoids two levels of buffering and copying the characters from one to the other. For an unbuffered stream (like stderr) the _File_sink buffer will still be used, to avoid the overhead of lots of small writes to the stream. Because this version of _File_sink accesses the stream's buffer directly it relies on glibc-specific implementation details that are exposed in public headers. A fallback definition of _File_sink just wraps a _Str_sink so is equivalent to the original code, and is used when flockfile isn't available. Both forms of std::println (taking a FILE* and a std::ostream) can be implemented more efficiently by appending a newline to the format string, to avoid formatting twice. PR libstdc++/121790 libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_CHECK_STDIO_LOCKING): New macro to check for std::print dependencies. * config.h.in: Regenerate. * configure: Regenerate. * configure.ac: Use GLIBCXX_CHECK_STDIO_LOCKING. * include/bits/formatfwd.h (enable_nonlocking_formatter_optimization): Define new variable template. * include/bits/version.def (print): Bump value. * include/bits/version.h: Regenerate. * include/std/format (enable_nonlocking_formatter_optimization): Define specializations for variable template. * include/std/ostream (print) [!_WIN32]: Do not use vprint_unicode at all. (println): Append newline to format string instead of formatting twice. * include/std/print (_File_sink): New class. (vprint_nonunicode_locking): New function. (vprint_unicode_locking): New function reusing previous code from vprint_unicode. (vprintf_unicode): Defer to vprint_nonunicode for Windows or to vprint_unicode_locking otherwise. (print): [!_WIN32]: Do no use vprint_unicode at all. Check enable_nonlocking_formatter_optimization and defer to either vprint_nonunicode_locking or vprint_nonunicode. (println): Use vprint_unicode or format directly to a _File_sink instead of formatting twice. * testsuite/27_io/print/1.cc: Updated and added new tests. * testsuite/std/format/formatter/nonlocking.cc: New tests. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Co-authored-by: Tomasz Kamiński <tkaminsk@redhat.com> |
||
|
|
71e95e871d |
libstdc++: Tweak comment on generated #endif lines in bits/version.h
Make the #endif comment match the #if condition in the generated code. Also adjust a comment in the Scheme code which describes the logic. The __glibcxx_NAME macro is not defined _unconditionally_, as it still depends on the conditions in cxxmin, extra_cond etca,. and the __cpp_lib_NAME macro now depends on no_stdname too. libstdc++-v3/ChangeLog: * include/bits/version.tpl: Fix comment on #endif. Tweak description of when macros are defined. * include/bits/version.h: Regenerate. Reviewed-by: Arsen Arsenović <arsen@aarsen.me> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> |
||
|
|
61061664e8 |
libstdc++: Implement strided_slice from <mdspan>. [PR110352]
Adds strided_slice as standardized in N5014. Also creates the internal feature testing macro for submdspan. PR libstdc++/110352 libstdc++-v3/ChangeLog: * include/bits/version.def (submdspan): New internal macro. * include/bits/version.h: Regenerate. * include/std/mdspan (strided_slice): New class. * src/c++23/std.cc.in (strided_slice): Add. * testsuite/23_containers/mdspan/submdspan/strided_slice.cc: New test. * testsuite/23_containers/mdspan/submdspan/strided_slice_neg.cc: New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com> |
||
|
|
8c71d18f54 |
libstdc++: Implement std::layout_left_padded [PR110352].
This commit adds a new layout layout_left_padded as standardized in N5014. It adds a purely internal feature testing macro padded_layouts and registers layout_left_padded in the std module. This commit implements LWG4372, because without it's not possible to properly test padded layouts with a dynamic padding value. It also implements LWG4314, for consistency with prior layouts. The implementation uses a _PaddedStorage to deduplicate most of the code shared between left- and right-padded layouts. It's implemented through aggregation rather than inheritence, because of a bug related to inheriting conditionally explicit ctors. The tests are written such that the canonical version works for layout_left_padded. A version for layout_right_padded is derived essentially by reversing the order of the extents. PR libstdc++/110352 libstdc++-v3/ChangeLog: * include/bits/version.def (padded_layouts): Add new internal feature testing macro. * include/bits/version.h: Regenerate. * include/std/mdspan (__fwd_prod): New overload. (layout_left_padded): Add declaration and implementation. (layout_right_padded): Add declaration only. (layout_left::mapping::mapping): New overload for left padded mappings. (__index_type_cast): New function that performs a checked cast to index_type. (__is_left_padded_mapping): New concept. (__is_right_padded_mapping): Ditto. (__standardized_mapping): Recognize left and right padded mappings. (_LeftPaddedIndices): Traits for left padded details. (_PaddedStorage): New class for implementing padded layouts. * src/c++23/std.cc.in (layout_left_padded): Add. * testsuite/23_containers/mdspan/layouts/class_mandate_neg.cc: Refactor and add tests for layout_left_padded. * testsuite/23_containers/mdspan/layouts/ctors.cc: Ditto. * testsuite/23_containers/mdspan/layouts/empty.cc: Ditto. * testsuite/23_containers/mdspan/layouts/mapping.cc: Ditto. * testsuite/23_containers/mdspan/layouts/padded.cc: Ditto. * testsuite/23_containers/mdspan/layouts/padded_neg.cc: Ditto. * testsuite/23_containers/mdspan/layouts/padded_traits.h: New traits. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com> |
||
|
|
1c06243e65 |
libstdc++: Implement Philox Engine (PR119794)
Conforms with errata LWG4143, LWG4153 for Philox Engine. PR libstdc++/119794 libstdc++-v3/ChangeLog: * include/bits/random.h (philox_engine): Define. * include/bits/random.tcc (philox_engine): Define member functions. * include/bits/version.def (philox_engine): New macro. * include/bits/version.h: Regenerated. * include/std/random: Define __glibcxx_want_philox_engine and include <bits/version.h>. * testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error line number. * testsuite/26_numerics/random/philox4x32.cc: New test. * testsuite/26_numerics/random/philox4x64.cc: New test. * testsuite/26_numerics/random/philox_engine/cons/119794.cc: New test. * testsuite/26_numerics/random/philox_engine/cons/copy.cc: New test. * testsuite/26_numerics/random/philox_engine/cons/default.cc: New test. * testsuite/26_numerics/random/philox_engine/cons/seed.cc: New test. * testsuite/26_numerics/random/philox_engine/cons/seed_seq.cc: New test. * testsuite/26_numerics/random/philox_engine/operators/equal.cc: New test. * testsuite/26_numerics/random/philox_engine/operators/inequal.cc: New test. * testsuite/26_numerics/random/philox_engine/operators/serialize.cc: New test. * testsuite/26_numerics/random/philox_engine/requirements/constants.cc: New test. * testsuite/26_numerics/random/philox_engine/requirements/constexpr_data.cc: New test. * testsuite/26_numerics/random/philox_engine/requirements/constexpr_functions.cc: New test. * testsuite/26_numerics/random/philox_engine/requirements/typedefs.cc: New test. |
||
|
|
a77146f015 |
libstdc++: Add NTTP bind_front, -back, not_fn (P2714) [PR119744]
Add non-type template parameter function-object/-pointer argument versions of bind_front, bind_back, and not_fn. This introduces a new internal type _Bind_fn_t to carry the template-argument function object when no arguments are bound, used in both bind_front and bind_back. Otherwise they return a lambda object that has captured the arguments. There is no need to change libstdc++-v3/src/c++23/std.cc.in because existing exports: "using std::bind_front;" etc. export the new overloads. libstdc++-v3/ChangeLog: PR libstdc++/119744 * include/bits/version.def: Redefine __cpp_lib_bind_front etc. * include/bits/version.h: Ditto. * include/std/functional: Add new bind_front etc. overloads * testsuite/20_util/function_objects/bind_back/1.cc: Check plumbing better * testsuite/20_util/function_objects/bind_back/nttp.cc: New test. * testsuite/20_util/function_objects/bind_back/nttp_neg.cc: New test. * testsuite/20_util/function_objects/bind_front/1.cc: Check plumbing better * testsuite/20_util/function_objects/bind_front/nttp.cc: New test. * testsuite/20_util/function_objects/bind_front/nttp_neg.cc: New test. * testsuite/20_util/function_objects/not_fn/nttp.cc: New test. * testsuite/20_util/function_objects/not_fn/nttp_neg.cc: New test. * testsuite/20_util/headers/functional/synopsis.cc: New decls. |
||
|
|
acfd5ab079 |
libstdc++: Reorder start_lifetime_as macro in version.def
libstdc++-v3/ChangeLog: * include/bits/version.def (start_lifetime_as): Move adjacent to other C++23 macros. * include/bits/version.h: Regenerate. |
||
|
|
c1e1691b95 |
libstdc++: Implement C++23 P2590R2 - Explicit lifetime management [PR106658]
As I can't think of how the middle-end would treat
__builtin_start_lifetime_as other than a blackbox and probably would
need to be implemented as such inline asm in RTL, this patch
just implements it using inline asm in the library.
If not anything else, it can serve as fallback before we and/or clang
get some builtin for it.
Right now the inline asms pretend (potential) read from and write to the whole
memory region and make optimizers forget where the return value points to.
If the optimizers don't know where it points to, I think that should be
good enough, but I'm a little bit afraid of possibly future optimizations
trying to optimize
q->c = 1;
q->d = 2;
auto p = std::start_lifetime_as<S>(q);
if (p == reinterpret_cast<decltype (p)>(q))
return p->a + p->b;
that because of the guarding condition or perhaps assertion we could
simply use the q pointer in MEM_REFs with S type and be surprised by TBAA.
Though if it is a must-alias case, then we should be fine as well.
Though guess that would be the same case with a builtin.
2025-09-18 Jakub Jelinek <jakub@redhat.com>
PR c++/106658
* include/bits/version.def: Implement C++23 P2590R2 - Explicit
lifetime management.
(start_lifetime_as): New.
* include/bits/version.h: Regenerate.
* include/std/memory (std::start_lifetime_as,
std::start_lifetime_as_array): New function templates.
* src/c++23/std.cc.in (std::start_lifetime_as,
std::start_lifetime_as_array): Export.
* testsuite/std/memory/start_lifetime_as/start_lifetime_as.cc: New test.
|
||
|
|
c440b585ba |
libstdc++: Implement constant_wrapper, cw from P2781R9.
This is a partial implementation of P2781R9. It adds std::cw and std::constant_wrapper, but doesn't modify __integral_constant_like for span/mdspan. libstdc++-v3/ChangeLog: * include/bits/version.def (constant_wrapper): Add. * include/bits/version.h: Regenerate. * include/std/type_traits (_CwFixedValue): New class. (_IndexSequence): New struct. (_BuildIndexSequence): New struct. (_ConstExprParam): New concept. (_CwOperators): New struct. (constant_wrapper): New struct. (cw): New global constant. * src/c++23/std.cc.in (constant_wrapper): Add. (cw): Add. * testsuite/20_util/constant_wrapper/adl.cc: New test. * testsuite/20_util/constant_wrapper/ex.cc: New test. * testsuite/20_util/constant_wrapper/generic.cc: New test. * testsuite/20_util/constant_wrapper/instantiate.cc: New test. * testsuite/20_util/constant_wrapper/op_comma_neg.cc: New test. * testsuite/20_util/constant_wrapper/version.cc: New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Co-authored-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com> |
||
|
|
381dbd4a95 |
libstdc++: Restore C++20 <chrono> support for old std::string ABI
The r16-3416-g806de30f51c8b9 change to use __cpp_lib_chrono in preprocessor conditions broke support for <chrono> for freestanding and the COW std::string ABI. That happened because __cpp_lib_chrono is only defined to the C++20 value for hosted and for the new ABI, because the full set of C++20 features are not defined for freestanding and tzdb is not defined for the old ABI. This introduces a new internal feature test macro that corresponds to the features that are always supported (e.g. chrono::local_time, chrono::year, chrono::weekday). libstdc++-v3/ChangeLog: * include/bits/version.def (chrono_cxx20): Define. * include/bits/version.h: Regenerate. * include/std/chrono: Check __glibcxx_chrono_cxx20 instead of __cpp_lib_chrono for C++20 features that don't require the new std::string ABI and/or can be used for freestanding. * src/c++20/clock.cc: Adjust preprocessor condition. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> |
||
|
|
3c95766e92 |
libstdc++: Implement C++26 <debugging> features [PR119670]
This implements P2546R5 (Debugging Support), including the P2810R4 (is_debugger_present is_replaceable) changes, allowing std::is_debugger_present to be replaced by the program. It would be good to provide a macOS definition of is_debugger_present as per https://developer.apple.com/library/archive/qa/qa1361/_index.html but that isn't included in this change. The src/c++26/debugging.cc file defines a global volatile int which can be set by debuggers to indicate when they are attached and detached from a running process. This allows std::is_debugger_present() to give a reliable answer, and additionally allows a debugger to choose how std::breakpoint() should behave. Setting the global to a positive value will cause std::breakpoint() to use that value as an argument to std::raise, so debuggers that prefer SIGABRT for breakpoints can select that. By default std::breakpoint() will use a platform-specific action such as the INT3 instruction on x86, or GCC's __builtin_trap(). On Linux the std::is_debugger_present() function checks whether the process is being traced by a process named "gdb", "gdbserver" or "lldb-server", to try to avoid interpreting other tracing processes (such as strace) as a debugger. There have been comments suggesting this isn't desirable and that std::is_debugger_present() should just return true for any tracing process (which is the case for non-Linux targets that support the ptrace system call). libstdc++-v3/ChangeLog: PR libstdc++/119670 * acinclude.m4 (GLIBCXX_CHECK_DEBUGGING): Check for facilities needed by <debugging>. * config.h.in: Regenerate. * configure: Regenerate. * configure.ac: Use GLIBCXX_CHECK_DEBUGGING. * include/Makefile.am: Add new header. * include/Makefile.in: Regenerate. * include/bits/version.def (debugging): Add. * include/bits/version.h: Regenerate. * include/precompiled/stdc++.h: Add new header. * src/c++26/Makefile.am: Add new file. * src/c++26/Makefile.in: Regenerate. * include/std/debugging: New file. * src/c++26/debugging.cc: New file. * testsuite/19_diagnostics/debugging/breakpoint.cc: New test. * testsuite/19_diagnostics/debugging/breakpoint_if_debugging.cc: New test. * testsuite/19_diagnostics/debugging/is_debugger_present.cc: New test. * testsuite/19_diagnostics/debugging/is_debugger_present-2.cc: New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> |
||
|
|
d147e7a20a |
libstdc++: Implement aligned_accessor from mdspan [PR120994]
This commit completes the implementation of P2897R7 by implementing and testing the template class aligned_accessor. PR libstdc++/120994 libstdc++-v3/ChangeLog: * include/bits/version.def (aligned_accessor): Add. * include/bits/version.h: Regenerate. * include/std/mdspan (aligned_accessor): New class. * src/c++23/std.cc.in (aligned_accessor): Add. * testsuite/23_containers/mdspan/accessors/generic.cc: Add tests for aligned_accessor. * testsuite/23_containers/mdspan/accessors/aligned_neg.cc: New test. * testsuite/23_containers/mdspan/version.cc: Add test for __cpp_lib_aligned_accessor. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com> |
||
|
|
5227ec972a |
libstdc++: Implement is_sufficiently_aligned [PR120994]
This commit implements and tests the function is_sufficiently_aligned from P2897R7. PR libstdc++/120994 libstdc++-v3/ChangeLog: * include/bits/align.h (is_sufficiently_aligned): New function. * include/bits/version.def (is_sufficiently_aligned): Add. * include/bits/version.h: Regenerate. * include/std/memory: Add __glibcxx_want_is_sufficiently_aligned. * src/c++23/std.cc.in (is_sufficiently_aligned): Add. * testsuite/20_util/headers/memory/version.cc: Add test for __cpp_lib_is_sufficiently_aligned. * testsuite/20_util/is_sufficiently_aligned/1.cc: New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com> |
||
|
|
985684e9b3 |
libstdc++: Implement std::dims from <mdspan>.
This commit implements the C++26 feature std::dims described in P2389R2. It sets the feature testing macro to 202406 and adds tests. Also fixes the test mdspan/version.cc libstdc++-v3/ChangeLog: * include/bits/version.def (mdspan): Set value for C++26. * include/bits/version.h: Regenerate. * include/std/mdspan (dims): Add. * src/c++23/std.cc.in (dims): Add. * testsuite/23_containers/mdspan/extents/misc.cc: Add tests. * testsuite/23_containers/mdspan/version.cc: Update test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com> |
||
|
|
9e33097738 |
libstdc++: Add std::inplace_vector for C++26 (P0843R14) [PR119137]
Implement std::inplace_vector as specified in P0843R14, without follow up papers, in particular P3074R7 (trivial unions). In consequence inplace_vector<T, N> can be used inside constant evaluations only if T is trivial or N is equal to zero. We provide a separate specialization for inplace_vector<T, 0> to meet the requirements of N5008 [inplace.vector.overview] p5. In particular objects of such types needs to be empty. To allow constexpr variable of inplace_vector v, where v.size() < v.capacity(), we need to guaranteed that all elements of the storage array are initialized, even ones in range [v.data() + v.size(), v.data() + v.capacity()). This is perfoirmed by _M_init function, that is called by each constructor. By storing the array in anonymous union, we can perform this initialization in constant evaluation, avoiding the impact on runtime path. The size() function conveys the information that _M_size <= _Nm to compiler, by calling __builtin_unreachable(). In particular this allows us to eliminate FP warnings by using _Nm - size() instead of _Nm - _M_size, when computing available elements. The included test cover almost all code paths at runtime, however some compile time evaluation test are not yet implemented: * operations on range, they depend on making testsuite_iterators constexpr * negative test for invoking operations with preconditions at compile time, especially for zero size specialization. PR libstdc++/119137 libstdc++-v3/ChangeLog: * doc/doxygen/user.cfg.in (INPUT): Add new header. * include/Makefile.am: Add new header. * include/Makefile.in: Regenerate. * include/bits/stl_iterator_base_types.h (__any_input_iterator): Define. * include/bits/version.def (inplace_vector): Define. * include/bits/version.h: Regenerate. * include/precompiled/stdc++.h: Include new header. * src/c++23/std.cc.in: Export contents if new header. * include/std/inplace_vector: New file. * testsuite/23_containers/inplace_vector/access/capacity.cc: New file. * testsuite/23_containers/inplace_vector/access/elem.cc: New file. * testsuite/23_containers/inplace_vector/access/elem_neg.cc: New file. * testsuite/23_containers/inplace_vector/cons/1.cc: New file. * testsuite/23_containers/inplace_vector/cons/from_range.cc: New file. * testsuite/23_containers/inplace_vector/cons/throws.cc: New file. * testsuite/23_containers/inplace_vector/copy.cc: New file. * testsuite/23_containers/inplace_vector/erasure.cc: New file. * testsuite/23_containers/inplace_vector/modifiers/assign.cc: New file. * testsuite/23_containers/inplace_vector/modifiers/erase.cc: New file. * testsuite/23_containers/inplace_vector/modifiers/multi_insert.cc: New file. * testsuite/23_containers/inplace_vector/modifiers/single_insert.cc: New file. * testsuite/23_containers/inplace_vector/move.cc: New file. * testsuite/23_containers/inplace_vector/relops.cc: New file. * testsuite/23_containers/inplace_vector/version.cc: New file. * testsuite/util/testsuite_iterators.h (input_iterator_wrapper::base): Define. Reviewed-by: Patrick Palka <ppalka@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Co-authored-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com> |
||
|
|
c163bbd75b |
libstdc++: Do not define __cpp_lib_constexpr_exceptions [PR121114]
Do not advertise library support for constexpr exceptions, as our solution to throwing by __throw_* functions from <bits/functexcept.h>, caues constant evaluation to fail, as these functions are not constexpr. PR libstdc++/121114 libstdc++-v3/ChangeLog: * include/bits/version.def (constexpr_exceptions): Add no_stdname and changed value. * include/bits/version.h: Regenerated. * testsuite/18_support/exception/version.cc: Test that macro is not exported. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kaminski <tkaminsk@redhat.com> |
||
|
|
9b6b7fed78 |
libstdc++: Correct value of __cpp_lib_constexpr_exceptions [PR117785]
Only P3068R6 (Allowing exception throwing in constant-evaluation) is implemented in the library so far, so the value of the constexpr_exceptions feature test macro should be 202411L. Once we support the library changes in P3378R2 (constexpr exception types) then we can set the value to 202502L again. libstdc++-v3/ChangeLog: PR libstdc++/117785 * include/bits/version.def (constexpr_exceptions): Define correct value. * include/bits/version.h: Regenerate. * libsupc++/exception: Check correct value. * testsuite/18_support/exception/version.cc: New test. |
||
|
|
baaee10123 |
c++, libstdc++: Implement C++26 P3068R5 - constexpr exceptions [PR117785]
The following patch implements the C++26 P3068R5 - constexpr exceptions
paper.
As the IL cxx_eval_constant* functions process already contains the low
level calls like __cxa_{allocate,free}_exception, __cxa_{,re}throw etc.,
the patch just makes 10 extern "C" __cxa_* functions magic builtins which
during constant evaluation pretend to be constexpr even when not declared
so and handle them directly, plus does the same for 3 std namespace
functions - std::uncaught_exceptions, std::current_exception and
std::rethrow_exception and adds one new FE builtin -
__builtin_eh_ptr_adjust_ref which the library can use instead of the
_M_addref and _M_release out of line methods (this one instead of
recognizing _M_* as magic too because those are clearly specific to
libstdc++ and e.g. libc++ could use something else).
The patch uses magic VAR_DECLs with heap_{uninit_,,deleted_}identifier
DECL_NAME like for operator new/delete for objects allocated with
__cxa_allocate_exception, just sets their DECL_LANG_SPECIFIC so that
we can track their reference count as well (with std::exception_ptr
the same exception object can be referenced multiple times and we want
to destruct and free only when it reaches zero refcount).
For uncaught exceptions being propagated, the patch uses new kind of
*jump_target, which is that magic VAR_DECL described above.
The largest change in the patch is making jump_target argument non-optional
in cxa_eval_constant_exception and all functions it calls that need it.
This is because exceptions can be thrown from pretty much everywhere, e.g.
binary expression can throw in either operand. And the patch also adds
if (*jump_target) return NULL_TREE; or similar in many spots, so that we
don't crash because cxx_eval_constant_expression returned NULL_TREE
somewhere before actually trying to use it and so that we don't uselessly
dive into other operands etc.
Note, with statement expressions actually this was something we just didn't
handle correctly before, one can validly have:
a = ({ if (x) return 42; 12; }) + b;
or in the other operand, or break/continue instead of return if it is
somewhere in a loop/switch; and it isn't ok to branch from one operand to
another one through some kind of goto.
On the potential_constant_expression_1 side, important change was to
set *jump_target conservatively on calls that could throw for C++26 (the
patch uses magic void_node for potential_constant_expression* instead of
VAR_DECL, so that we don't have to create new VAR_DECLs there uselessly).
Without that change, several methods in libstdc++ wouldn't work correctly.
I'm not sure what exactly potential_constant_expression_1 maps to in the
C++26 standard wording now and whether doing that is ok, because basically
after the first call to non-noexcept function it stops checking stuff.
And, in some spots where I know potential_constant_expression_1 didn't
check some subexpressions (e.g. the EH only cleanups or TRY_BLOCK handlers)
I've added *potential_constant_expression* calls during cxx_eval_constant*,
not sure if I need to do that because potential_constant_expression_1 is
very conservative and just doesn't recurse on subexpressions in many cases.
2025-07-10 Jakub Jelinek <jakub@redhat.com>
PR c++/117785
gcc/c-family/
* c-cppbuiltin.cc (c_cpp_builtins): Predefine
__cpp_constexpr_exceptions=202411L for C++26.
gcc/cp/
* constexpr.cc: Implement C++26 P3068R5 - constexpr exceptions.
(class constexpr_global_ctx): Add caught_exceptions and
uncaught_exceptions members.
(constexpr_global_ctx::constexpr_global_ctx): Initialize
uncaught_exceptions.
(returns, breaks, continues, switches): Move earlier.
(throws): New function.
(exception_what_str, diagnose_std_terminate,
diagnose_uncaught_exception): New functions.
(enum cxa_builtin): New type.
(cxx_cxa_builtin_fn_p, cxx_eval_cxa_builtin_fn): New functions.
(cxx_eval_builtin_function_call): Add jump_target argument. Call
cxx_eval_cxa_builtin_fn for __builtin_eh_ptr_adjust_ref. Adjust
cxx_eval_constant_expression calls, if it results in jmp_target,
set *jump_target to it and return.
(cxx_bind_parameters_in_call): Add jump_target argument. Pass
it through to cxx_eval_constant_expression. If it sets *jump_target,
break.
(fold_operand): Adjust cxx_eval_constant_expression caller.
(cxx_eval_assert): Likewise. If it set jmp_target, return true.
(cxx_eval_internal_function): Add jump_target argument. Pass it
through to cxx_eval_constant_expression. Return early if *jump_target
after recursing on args.
(cxx_eval_dynamic_cast_fn): Likewise. Don't set reference_p for
C++26 with -fexceptions.
(cxx_eval_thunk_call): Add jump_target argument. Pass it through
to cxx_eval_constant_expression.
(cxx_set_object_constness): Likewise. Don't set TREE_READONLY if
throws (jump_target).
(cxx_eval_call_expression): Add jump_target argument. Pass it
through to cxx_eval_internal_function, cxx_eval_builtin_function_call,
cxx_eval_thunk_call, cxx_eval_dynamic_cast_fn and
cxx_set_object_constness. Pass it through also
cxx_eval_constant_expression on arguments, cxx_bind_parameters_in_call
and cxx_fold_indirect_ref and for those cases return early
if *jump_target. Call cxx_eval_cxa_builtin_fn for cxx_cxa_builtin_fn_p
functions. For cxx_eval_constant_expression on body, pass address of
cleared jmp_target automatic variable, if it throws propagate
to *jump_target and make it non-cacheable. For C++26 don't diagnose
calls to non-constexpr functions before cxx_bind_parameters_in_call
could report some argument throwing an exception.
(cxx_eval_unary_expression): Add jump_target argument. Pass it
through to cxx_eval_constant_expression and return early
if *jump_target after the call.
(cxx_fold_pointer_plus_expression): Likewise.
(cxx_eval_binary_expression): Likewise and similarly for
cxx_fold_pointer_plus_expression call.
(cxx_eval_conditional_expression): Pass jump_target to
cxx_eval_constant_expression on first operand and return early
if *jump_target after the call.
(cxx_eval_vector_conditional_expression): Add jump_target argument.
Pass it through to cxx_eval_constant_expression for all 3 arguments
and return early if *jump_target after any of those calls.
(get_array_or_vector_nelts): Add jump_target argument. Pass it
through to cxx_eval_constant_expression.
(eval_and_check_array_index): Add jump_target argument. Pass it
through to cxx_eval_constant_expression calls and return early after
each of them if *jump_target.
(cxx_eval_array_reference): Likewise.
(cxx_eval_component_reference): Likewise.
(cxx_eval_bit_field_ref): Likewise.
(cxx_eval_bit_cast): Likewise. Assert CHECKING_P call doesn't
throw or return.
(cxx_eval_logical_expression): Add jump_target argument. Pass it
through to cxx_eval_constant_expression calls and return early after
each of them if *jump_target.
(cxx_eval_bare_aggregate): Likewise.
(cxx_eval_vec_init_1): Add jump_target argument. Pass it through
to cxx_eval_bare_aggregate and recursive call. Pass it through
to get_array_or_vector_nelts and cxx_eval_constant_expression
and return early after it if *jump_target.
(cxx_eval_vec_init): Add jump_target argument. Pass it through
to cxx_eval_constant_expression and cxx_eval_vec_init_1.
(cxx_union_active_member): Add jump_target argument. Pass it
through to cxx_eval_constant_expression and return early after it
if *jump_target.
(cxx_fold_indirect_ref_1): Add jump_target argument. Pass it
through to cxx_union_active_member and recursive calls.
(cxx_eval_indirect_ref): Add jump_target argument. Pass it through
to cxx_fold_indirect_ref_1 calls and to recursive call, in which
case return early after it if *jump_target.
(cxx_fold_indirect_ref): Add jump_target argument. Pass it through
to cxx_fold_indirect_ref and cxx_eval_constant_expression calls and
return early after those if *jump_target.
(cxx_eval_trinary_expression): Add jump_target argument. Pass it
through to cxx_eval_constant_expression calls and return early after
those if *jump_target.
(cxx_eval_store_expression): Add jump_target argument. Pass it
through to cxx_eval_constant_expression and eval_and_check_array_index
calls and return early after those if *jump_target.
(cxx_eval_increment_expression): Add jump_target argument. Pass it
through to cxx_eval_constant_expression calls and return early after
those if *jump_target.
(label_matches): Handle VAR_DECL case.
(cxx_eval_statement_list): Remove local_target variable and
!jump_target handling. Handle throws (jump_target) like returns or
breaks.
(cxx_eval_loop_expr): Remove local_target variable and !jump_target
handling. Pass it through to cxx_eval_constant_expression. Handle
throws (jump_target) like returns.
(cxx_eval_switch_expr): Pass jump_target through to
cxx_eval_constant_expression on cond, return early after it
if *jump_target.
(build_new_constexpr_heap_type): Add jump_target argument. Pass it
through to cxx_eval_constant_expression calls, return early after
those if *jump_target.
(merge_jump_target): New function.
(cxx_eval_constant_expression): Make jump_target argument no longer
defaulted, don't test jump_target for NULL. Pass jump_target
through to recursive calls, cxx_eval_call_expression,
cxx_eval_store_expression, cxx_eval_indirect_ref,
cxx_eval_unary_expression, cxx_eval_binary_expression,
cxx_eval_logical_expression, cxx_eval_array_reference,
cxx_eval_component_reference, cxx_eval_bit_field_ref,
cxx_eval_vector_conditional_expression, cxx_eval_bare_aggregate,
cxx_eval_vec_init, cxx_eval_trinary_expression, cxx_fold_indirect_ref,
build_new_constexpr_heap_type, cxx_eval_increment_expression,
cxx_eval_bit_cast and return earlyu after some of those
if *jump_target as needed.
(cxx_eval_constant_expression) <case TARGET_EXPR>: For C++26 push
also CLEANUP_EH_ONLY cleanups, with NULL_TREE marker after them.
(cxx_eval_constant_expression) <case RETURN_EXPR>: Don't
override *jump_target if throws (jump_target).
(cxx_eval_constant_expression) <case TRY_CATCH_EXPR, case TRY_BLOCK,
case MUST_NOT_THROW_EXPR, case TRY_FINALLY_EXPR, case CLEANUP_STMT>:
Handle C++26 constant expressions.
(cxx_eval_constant_expression) <case CLEANUP_POINT_EXPR>: For C++26
with throws (jump_target) evaluate the CLEANUP_EH_ONLY cleanups as
well, and if not throws (jump_target) skip those. Set *jump_target
if some of the cleanups threw.
(cxx_eval_constant_expression) <case THROW_EXPR>: Recurse on operand
for C++26.
(cxx_eval_outermost_constant_expr): Diagnose uncaught exceptions both
from main expression and cleanups, diagnose also
break/continue/returns from the main expression. Handle
CLEANUP_EH_ONLY cleanup markers. Don't diagnose mutable poison stuff
if non_constant_p. Use different diagnostics for non-deleted heap
allocations if they were allocated by __cxa_allocate_exception.
(callee_might_throw): New function.
(struct check_for_return_continue_data): Add could_throw field.
(check_for_return_continue): Handle AGGR_INIT_EXPR and CALL_EXPR and
set d->could_throw if they could throw.
(potential_constant_expression_1): For CALL_EXPR allow
cxx_dynamic_cast_fn_p calls. For C++26 set *jump_target to void_node
for calls that could throw. For C++26 if call to non-constexpr call
is seen, try to evaluate arguments first and if they could throw,
don't diagnose call to non-constexpr function nor return false.
Adjust check_for_return_continue_data initializers and
set *jump_target to void_node if data.could_throw_p. For C++26
recurse on THROW_EXPR argument. Add comment explaining TRY_BLOCK
handling with C++26 exceptions. Handle throws like returns in some
cases.
* cp-tree.h (MUST_NOT_THROW_NOEXCEPT_P, MUST_NOT_THROW_THROW_P,
MUST_NOT_THROW_CATCH_P, DECL_EXCEPTION_REFCOUNT): Define.
(DECL_LOCAL_DECL_P): Fix comment typo, VARIABLE_DECL -> VAR_DECL.
(enum cp_built_in_function): Add CP_BUILT_IN_EH_PTR_ADJUST_REF,
(handler_match_for_exception_type): Declare.
* call.cc (handler_match_for_exception_type): New function.
* except.cc (initialize_handler_parm): Set MUST_NOT_THROW_CATCH_P
on newly created MUST_NOT_THROW_EXPR.
(begin_eh_spec_block): Set MUST_NOT_THROW_NOEXCEPT_P.
(wrap_cleanups_r): Set MUST_NOT_THROW_THROW_P.
(build_throw): Add another TARGET_EXPR whose scope spans
until after the __cxa_throw call and copy pointer value from ptr
to it and use it in __cxa_throw argument.
* tree.cc (builtin_valid_in_constant_expr_p): Handle
CP_BUILT_IN_EH_PTR_ADJUST_REF.
* decl.cc (cxx_init_decl_processing): Initialize
__builtin_eh_ptr_adjust_ref FE builtin.
* pt.cc (tsubst_stmt) <case MUST_NOT_THROW_EXPR>: Copy the
MUST_NOT_THROW_NOEXCEPT_P, MUST_NOT_THROW_THROW_P and
MUST_NOT_THROW_CATCH_P flags.
* cp-gimplify.cc (cp_gimplify_expr) <case CALL_EXPR>: Error on
non-folded CP_BUILT_IN_EH_PTR_ADJUST_REF calls.
gcc/testsuite/
* g++.dg/cpp0x/constexpr-ellipsis2.C: Expect different diagnostics for
C++26.
* g++.dg/cpp0x/constexpr-throw.C: Likewise.
* g++.dg/cpp1y/constexpr-84192.C: Expect different diagnostics.
* g++.dg/cpp1y/constexpr-throw.C: Expect different diagnostics for
C++26.
* g++.dg/cpp1z/constexpr-asm-5.C: Likewise.
* g++.dg/cpp26/constexpr-eh1.C: New test.
* g++.dg/cpp26/constexpr-eh2.C: New test.
* g++.dg/cpp26/constexpr-eh3.C: New test.
* g++.dg/cpp26/constexpr-eh4.C: New test.
* g++.dg/cpp26/constexpr-eh5.C: New test.
* g++.dg/cpp26/constexpr-eh6.C: New test.
* g++.dg/cpp26/constexpr-eh7.C: New test.
* g++.dg/cpp26/constexpr-eh8.C: New test.
* g++.dg/cpp26/constexpr-eh9.C: New test.
* g++.dg/cpp26/constexpr-eh10.C: New test.
* g++.dg/cpp26/constexpr-eh11.C: New test.
* g++.dg/cpp26/constexpr-eh12.C: New test.
* g++.dg/cpp26/constexpr-eh13.C: New test.
* g++.dg/cpp26/constexpr-eh14.C: New test.
* g++.dg/cpp26/constexpr-eh15.C: New test.
* g++.dg/cpp26/feat-cxx26.C: Change formatting in __cpp_pack_indexing
and __cpp_pp_embed test. Add __cpp_constexpr_exceptions test.
* g++.dg/cpp26/static_assert1.C: Expect different diagnostics for
C++26.
* g++.dg/cpp2a/consteval34.C: Likewise.
* g++.dg/cpp2a/consteval-memfn1.C: Likewise.
* g++.dg/cpp2a/constexpr-dynamic4.C: For C++26 add std::exception and
std::bad_cast definitions and expect different diagnostics.
* g++.dg/cpp2a/constexpr-dynamic6.C: Likewise.
* g++.dg/cpp2a/constexpr-dynamic7.C: Likewise.
* g++.dg/cpp2a/constexpr-dynamic8.C: Likewise.
* g++.dg/cpp2a/constexpr-dynamic9.C: Likewise.
* g++.dg/cpp2a/constexpr-dynamic11.C: Likewise.
* g++.dg/cpp2a/constexpr-dynamic14.C: Likewise.
* g++.dg/cpp2a/constexpr-dynamic18.C: Likewise.
* g++.dg/cpp2a/constexpr-new27.C: New test.
* g++.dg/cpp2a/constexpr-typeid5.C: New test.
libstdc++-v3/
* include/bits/version.def (constexpr_exceptions): New.
* include/bits/version.h: Regenerate.
* libsupc++/exception (std::bad_exception::bad_exception): Add
_GLIBCXX26_CONSTEXPR.
(std::bad_exception::~bad_exception, std::bad_exception::what): For
C++26 add constexpr and define inline.
* libsupc++/exception.h (std::exception::exception,
std::exception::operator=): Add _GLIBCXX26_CONSTEXPR.
(std::exception::~exception, std::exception::what): For C++26 add
constexpr and define inline.
* libsupc++/exception_ptr.h (std::make_exception_ptr): Add
_GLIBCXX26_CONSTEXPR. For if consteval use just throw with
current_exception() in catch.
(std::exception_ptr::exception_ptr(void*)): For C++26 add constexpr
and define inline.
(std::exception_ptr::exception_ptr()): Add _GLIBCXX26_CONSTEXPR.
(std::exception_ptr::exception_ptr(const exception_ptr&)): Likewise.
Use __builtin_eh_ptr_adjust_ref if consteval and compiler has it
instead of _M_addref.
(std::exception_ptr::exception_ptr(nullptr_t)): Add
_GLIBCXX26_CONSTEXPR.
(std::exception_ptr::exception_ptr(exception_ptr&&)): Likewise.
(std::exception_ptr::operator=): Likewise.
(std::exception_ptr::~exception_ptr): Likewise. Use
__builtin_eh_ptr_adjust_ref if consteval and compiler has it
instead of _M_release.
(std::exception_ptr::swap): Add _GLIBCXX26_CONSTEXPR.
(std::exception_ptr::operator bool): Likewise.
(std::exception_ptr::operator==): Likewise.
* libsupc++/nested_exception.h
(std::nested_exception::nested_exception): Add _GLIBCXX26_CONSTEXPR.
(std::nested_exception::operator=): Likewise.
(std::nested_exception::~nested_exception): For C++26 add constexpr
and define inline.
(std::nested_exception::rethrow_if_nested): Add _GLIBCXX26_CONSTEXPR.
(std::nested_exception::nested_ptr): Likewise.
(std::_Nested_exception::_Nested_exception): Likewise.
(std::throw_with_nested, std::rethrow_if_nested): Likewise.
* libsupc++/new (std::bad_alloc::bad_alloc): Likewise.
(std::bad_alloc::operator=): Likewise.
(std::bad_alloc::~bad_alloc): For C++26 add constexpr and define
inline.
(std::bad_alloc::what): Likewise.
(std::bad_array_new_length::bad_array_new_length): Add
_GLIBCXX26_CONSTEXPR.
(std::bad_array_new_length::~bad_array_new_length): For C++26 add
constexpr and define inline.
(std::bad_array_new_length::what): Likewise.
* libsupc++/typeinfo (std::bad_cast::bad_cast): Add
_GLIBCXX26_CONSTEXPR.
(std::bad_cast::~bad_cast): For C++26 add constexpr and define inline.
(std::bad_cast::what): Likewise.
(std::bad_typeid::bad_typeid): Add _GLIBCXX26_CONSTEXPR.
(std::bad_typeid::~bad_typeid): For C++26 add constexpr and define
inline.
(std::bad_typeid::what): Likewise.
|
||
|
|
10b8379252 |
libstdc++: Add smart ptr owner_equals and owner_hash [PR117403]
New structs and member functions added to C++26 by P1901R2. libstdc++-v3/ChangeLog: PR libstdc++/117403 * include/bits/shared_ptr.h (shared_ptr::owner_equal) (shared_ptr::owner_hash, weak_ptr::owner_equal) (weak_ptr::owner_hash): Define new member functions. * include/bits/shared_ptr_base.h (owner_equal, owner_hash): Define new structs. * include/bits/version.def (smart_ptr_owner_equality): Define. * include/bits/version.h: Regenerate. * include/std/memory: Added define for __glibcxx_want_smart_ptr_owner_equality. * testsuite/20_util/owner_equal/version.cc: New test. * testsuite/20_util/owner_equal/cmp.cc: New test. * testsuite/20_util/owner_equal/noexcept.cc: New test. * testsuite/20_util/owner_hash/cmp.cc: New test. * testsuite/20_util/owner_hash/noexcept.cc: New test. * testsuite/20_util/shared_ptr/observers/owner_equal.cc: New test. * testsuite/20_util/shared_ptr/observers/owner_hash.cc: New test. * testsuite/20_util/weak_ptr/observers/owner_equal.cc: New test. * testsuite/20_util/weak_ptr/observers/owner_hash.cc: New test. Signed-off-by: Paul Keir <paul.keir@uws.ac.uk> |
||
|
|
7b3b315e48 |
libstdc++: Set feature test macro for complete C++23 mdspan [PR107761].
PR libstdc++/107761 libstdc++-v3/ChangeLog: * include/bits/version.def (mdspan): Set to 202207 and remove no_stdname. * include/bits/version.h: Regenerate. * testsuite/23_containers/mdspan/version.cc: Test presence of feature test macro. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com> |
||
|
|
2a56f3c539 |
libstdc++: Implement ranges::shift_left/right from P2440R1
The implementation is just a copy of std::shift_left/right with the
following changes:
- check bidirectional_iterator instead of iterator_category
- cope with __last being a distinct sentinel type
- for shift_left, return the subrange {__first, X} instead of X
- for shift_right, return the subrange {X, ranges::next(__first, __last)}
instead of X
- use the ranges:: versions of move_backward, move and iter_swap
- don't bother std::move'ing any iterators, it's unnecessary since all
iterators are forward, it's visually noisy, and in earlier versions
of this patch it introduced subtle use-after-move bugs
In passing also use the __glibcxx_shift macro to guard the
std::shift_left/right implementations.
libstdc++-v3/ChangeLog:
* include/bits/ranges_algo.h (shift_left, shift_right): Guard
with __glibcxx_shift >= 201806L.
(ranges::__shift_left_fn, ranges::shift_left): Define for C++23.
(ranges::__shift_right_fn, ranges::shift_right): Likewise.
* include/bits/version.def (shift): Update for C++23.
* include/bits/version.h: Regenerate.
* src/c++23/std.cc.in: Add ranges::shift_left/right.
* testsuite/25_algorithms/shift_left/constrained.cc: New test,
based off of 1.cc.
* testsuite/25_algorithms/shift_right/constrained.cc: New test,
based off of 1.cc.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
|
||
|
|
062f217f41 |
libstdc++: fix bits/version.def typo
bits/version.def was missing a ';'. libstdc++-v3/Changelog: * include/bits/version.def: Fix typo. * include/bits/version.h: Rebuilt. |
||
|
|
9930876ed7 |
libstdc++: construct bitset from string_view (P2697) [PR119742]
Add a bitset constructor from string_view, per P2697. Fix existing tests that would fail to detect incorrect exception behavior. Argument checks that result in exceptions guarded by "#if HOSTED" are made unguarded because the functions called to throw just call terminate() in free-standing builds. Improve readability in Doxygen comments. Generalize a private member argument-checking function to work with string and string_view without mentioning either, obviating need for guards. The version.h symbol is not "hosted" because string_view, though not specified to be available in free-standing builds, is defined there and the feature is useful there. libstdc++-v3/ChangeLog: PR libstdc++/119742 * include/bits/version.def: Add preprocessor symbol. * include/bits/version.h: Add preprocessor symbol. * include/std/bitset: Add constructor. * testsuite/20_util/bitset/cons/1.cc: Fix. * testsuite/20_util/bitset/cons/6282.cc: Fix. * testsuite/20_util/bitset/cons/string_view.cc: Test new ctor. * testsuite/20_util/bitset/cons/string_view_wide.cc: Test new ctor. |
||
|
|
af5b72cf9f |
libstdc++: Implement C++26 P2927R3 - Inspecting exception_ptr
The following patch attempts to implement the C++26 P2927R3 - Inspecting exception_ptr paper (but not including P3748R0, I plan to play with it incrementally and it will really depend on the Constexpr exceptions patch). The function template is implemented using an out of line private method of exception_ptr, so that P3748R0 then can use if consteval and provide a constant evaluation variant of it. 2025-06-26 Jakub Jelinek <jakub@redhat.com> * include/bits/version.def (exception_ptr_cast): Add. * include/bits/version.h: Regenerate. * libsupc++/exception: Define __glibcxx_want_exception_ptr_cast before including bits/version.h. * libsupc++/exception_ptr.h (std::exception_ptr_cast): Define. (std::__exception_ptr::exception_ptr::_M_exception_ptr_cast): Declare. * libsupc++/eh_ptr.cc (std::__exception_ptr::exception_ptr::_M_exception_ptr_cast): Define. * src/c++23/std.cc.in (std::exception_ptr_cast): Export. * config/abi/pre/gnu.ver: Export _ZNKSt15__exception_ptr13exception_ptr21_M_exception_ptr_castERKSt9type_info at CXXABI_1.3.17. * testsuite/util/testsuite_abi.cc (check_version): Allow CXXABI_1.3.17. * testsuite/18_support/exception_ptr/exception_ptr_cast.cc: New test. |
||
|
|
29c7661c6f |
c++, libstdc++: Implement C++26 P2830R10 - Constexpr Type Ordering
The following patch attempts to implement the C++26 P2830R10 - Constexpr Type Ordering paper, with a minor change that std::type_order<T, U> class template doesn't derive from integer_constant, because std::strong_ordering is not a structural type (except in MSVC), so instead it is just a class template with static constexpr strong_ordering value member and also value_type, type and 2 operators. The paper mostly talks about using something other than mangled names for the ordering, but given that the mangler is part of the GCC C++ FE, using the mangler seems to be the best ordering choice to me. 2025-06-26 Jakub Jelinek <jakub@redhat.com> gcc/cp/ * cp-trait.def: Implement C++26 P2830R10 - Constexpr Type Ordering. (TYPE_ORDER): New. * method.cc (type_order_value): Define. * cp-tree.h (type_order_value): Declare. * semantics.cc (trait_expr_value): Use gcc_unreachable also for CPTK_TYPE_ORDER, adjust comment. (finish_trait_expr): Handle CPTK_TYPE_ORDER. * constraint.cc (diagnose_trait_expr): Likewise. gcc/testsuite/ * g++.dg/cpp26/type-order1.C: New test. * g++.dg/cpp26/type-order2.C: New test. * g++.dg/cpp26/type-order3.C: New test. libstdc++-v3/ * include/bits/version.def (type_order): New. * include/bits/version.h: Regenerate. * libsupc++/compare: Define __glibcxx_want_type_order before including bits/version.h. (std::type_order, std::type_order_v): New trait and template variable. * src/c++23/std.cc.in (std::type_order, std::type_order_v): Export. * testsuite/18_support/comparisons/type_order/1.cc: New test. |
||
|
|
774ae8734f |
libstdc++: add range support to std::optional (P3168)
This commit implements P3168 ("Give std::optional Range Support"), added
for C++26. Both begin() and end() are straightforward, implemented using
normal_iterator over a raw pointer.
std::optional is also a view, so specialize enable_view for it.
We also need to disable automatic formatting a std::optional as a range
by specializing format_kind. In order to avoid dragging <format> when
including <optional>, I've isolated format_kind and some supporting code
into <bits/formatfwd.h> so that I can use that (comparatively) lighter
header.
libstdc++-v3/ChangeLog:
* include/bits/formatfwd.h (format_kind): Move the definition
(and some supporting code) from <format>.
* include/std/format (format_kind): Likewise.
* include/bits/version.def (optional_range_support): Add
the feature-testing macro.
* include/bits/version.h: Regenerate.
* include/std/optional (iterator, const_iterator, begin, end):
Add range support.
(enable_view): Specialize for std::optional.
(format_kind): Specialize for std::optional.
* testsuite/20_util/optional/range.cc: New test.
* testsuite/20_util/optional/version.cc: Test the new
feature-testing macro.
|
||
|
|
845826088c |
libstdc++: sstream from string_view (P2495R3) [PR119741]
Add constructors to stringbuf, stringstream, istringstream, and ostringstream, and a matching overload of str(sv) in each, that take anything convertible to a string_view in places where the existing ctors and function take a string. Note this change omits the constraint applied to the istringstream constructor from string cited as a "drive-by" in P2495R3, as we have determined it is redundant. libstdc++-v3/ChangeLog: PR libstdc++/119741 * include/std/sstream: full implementation, really just decls, requires clause and plumbing. * include/bits/version.def, include/bits/version.h: new preprocessor symbol __cpp_lib_sstream_from_string_view. * testsuite/27_io/basic_stringbuf/cons/char/string_view.cc: New tests. * testsuite/27_io/basic_istringstream/cons/char/string_view.cc: New tests. * testsuite/27_io/basic_ostringstream/cons/char/string_view.cc: New tests. * testsuite/27_io/basic_stringstream/cons/char/string_view.cc: New tests. * testsuite/27_io/basic_stringbuf/cons/wchar_t/string_view.cc: New tests. * testsuite/27_io/basic_istringstream/cons/wchar_t/string_view.cc: New tests. * testsuite/27_io/basic_ostringstream/cons/wchar_t/string_view.cc: New tests. * testsuite/27_io/basic_stringstream/cons/wchar_t/string_view.cc: New tests. Reviewed-by: Jonathan Wakely |
||
|
|
a31e76a264 |
Revert "libstdc++: sstream from string_view (P2495R3) [PR119741]"
This reverts commit
|
||
|
|
8537e48510 |
libstdc++: sstream from string_view (P2495R3) [PR119741]
Add constructors to stringbuf, stringstream, istringstream, and ostringstream, and a matching overload of str(sv) in each, that take anything convertible to a string_view in places where the existing ctors and function take a string. Note this change omits the constraint applied to the istringstream constructor from string cited as a "drive-by" in P2495R3, as we have determined it is redundant. libstdc++-v3/ChangeLog: PR libstdc++/119741 * include/std/sstream: full implementation, really just decls, requires clause and plumbing. * include/bits/version.def, include/bits/version.h: new preprocessor symbol __cpp_lib_sstream_from_string_view. * testsuite/27_io/basic_stringbuf/cons/char/string_view.cc: New tests. * testsuite/27_io/basic_istringstream/cons/char/string_view.cc: New tests. * testsuite/27_io/basic_ostringstream/cons/char/string_view.cc: New tests. * testsuite/27_io/basic_stringstream/cons/char/string_view.cc: New tests. * testsuite/27_io/basic_stringbuf/cons/wchar_t/string_view.cc: New tests. * testsuite/27_io/basic_istringstream/cons/wchar_t/string_view.cc: New tests. * testsuite/27_io/basic_ostringstream/cons/wchar_t/string_view.cc: New tests. * testsuite/27_io/basic_stringstream/cons/wchar_t/string_view.cc: New tests. |
||
|
|
6545e2f301 |
libstdc++: Implement C++23 P1659R3 starts_with and ends_with
This implements ranges::starts_with and ranges::ends_with from the C++23 paper P1659R3. The corresponding_S_impl member functions take optional optional size parameters __n1 and __n2 of the two ranges, where -1 means the corresponding size is not known. libstdc++-v3/ChangeLog: * include/bits/ranges_algo.h (__starts_with_fn, starts_with): Define. (__ends_with_fn, ends_with): Define. * include/bits/version.def (ranges_starts_ends_with): Define. * include/bits/version.h: Regenerate. * include/std/algorithm: Provide __cpp_lib_ranges_starts_ends_with. * src/c++23/std.cc.in (ranges::starts_with): Export. (ranges::ends_with): Export. * testsuite/25_algorithms/ends_with/1.cc: New test. * testsuite/25_algorithms/starts_with/1.cc: New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com> |