aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include
AgeCommit message (Collapse)AuthorFilesLines
2022-11-07libstdc++: Implement ranges::as_rvalue_view from P2446R2Patrick Palka1-0/+90
libstdc++-v3/ChangeLog: * include/std/ranges (as_rvalue_view): Define. (enable_borrowed_range<as_rvalue_view>): Define. (views::__detail::__can_as_rvalue_view): Define. (views::_AsRvalue, views::as_rvalue): Define. * testsuite/std/ranges/adaptors/as_rvalue/1.cc: New test.
2022-11-07libstdc++: Implement ranges::cartesian_product_view from P2374R4Patrick Palka1-0/+513
This also implements the proposed resolutions of the tentatively ready LWG issues 3760, 3761 and 3801 for cartesian_product_view. I'm not sure how/if we should implement the recommended practice of: iterator::difference_type should be the smallest signed-integer-like type that is sufficiently wide to store the product of the maximum sizes of all underlying ranges if such a type exists because for e.g. extern std::vector<int> x, y; auto v = views::cartesian_product(x, y); IIUC it'd mean difference_type should be __int128 (on 64-bit systems), which seems quite wasteful: in practice the size of any cartesian product probably won't exceed the precision of say ptrdiff_t, and using anything larger will just incur unnecessary space/time overhead. It's also probably not worth the complexity to use less precision than ptrdiff_t (when possible) either. So this patch defines difference_type as common_type_t<ptrdiff_t, range_difference_t<_First>, range_difference_t<_Vs>...> which should mean it's least as large as the difference_type of each underlying range, and at least as large as ptrdiff_t. This patch also adds assertions to catch any overflow that occurs due to this choice of difference_type. libstdc++-v3/ChangeLog: * include/std/ranges (__maybe_const_t): New alias for __detail::__maybe_const_t. (__detail::__cartesian_product_is_random_access): Define. (__detail::__cartesian_product_common_arg): Define. (__detail::__cartesian_product_is_bidirectional): Define. (__detail::__cartesian_product_is_common): Define. (__detail::__cartesian_product_is_sized): Define. (__detail::__cartesian_is_sized_sentinel): Define. (__detail::__cartesian_common_arg_end): Define. (cartesian_product_view): Define. (cartesian_product_view::_Iterator): Define. (views::__detail::__can_cartesian_product_view): Define. (views::_CartesianProduct, views::cartesian_product): Define. * testsuite/std/ranges/cartesian_product/1.cc: New test.
2022-11-07libstdc++: Add _Float128 to_chars/from_chars support for x86, ia64 and ↵Jakub Jelinek1-0/+61
ppc64le with glibc The following patch adds std::{to,from}_chars support for std::float128_t on glibc 2.26+ for {i?86,x86_64,ia64,powerpc64le}-linux. When long double is already IEEE quad, previous changes already handle it by using long double overloads in _Float128 overloads. The powerpc64le case (with explicit or implicit -mabi=ibmlongdouble) is handled by using the __float128/__ieee128 entrypoints which are already in the library and used for -mabi=ieeelongdouble. For i?86, x86_64 and ia64 this patch adds new library entrypoints, mostly by enabling the code that was already there for powerpc64le-linux. Those use __float128 or __ieee128, the patch uses _Float128 for the exported overloads and internally as template parameter. While powerpc64le-linux uses __sprintfieee128 and __strtoieee128, for _Float128 the patch uses the glibc 2.26 strfromf128 and strtof128 APIs. So that one can build gcc against older glibc and then compile user programs on newer glibc, the patch uses weak references unless gcc is compiled against glibc 2.26+. strfromf128 unfortunately can't handle %.0Lf and %.*Le, %.*Lf, %.*Lg format strings sprintf/__sprintfieee128 use, we need to remove the L from those and replace * with actually directly printing the precision into the format string (i.e. it can handle %.0f and %.27f (floating point type is implied from the function name)). Unlike the std::{,b}float16_t support, this one actually exports APIs with std::float128_t aka _Float128 in the mangled name, because no standard format is superset of it. On the other side, e.g. on i?86/x86_64 it doesn't have restrictions like for _Float16/__bf16 which ISAs need to be enabled in order to use it. The denorm_min case in the testcase is temporarily commented out because of the ERANGE subnormal issue Patrick posted patch for. 2022-11-07 Jakub Jelinek <jakub@redhat.com> * include/std/charconv (from_chars, to_chars): Add _Float128 overfloads if _GLIBCXX_HAVE_FLOAT128_MATH is defined. * config/abi/pre/gnu.ver (GLIBCXX_3.4.31): Export _ZSt8to_charsPcS_DF128_, _ZSt8to_charsPcS_DF128_St12chars_format, _ZSt8to_charsPcS_DF128_St12chars_formati and _ZSt10from_charsPKcS0_RDF128_St12chars_format. * src/c++17/floating_from_chars.cc (USE_STRTOF128_FOR_FROM_CHARS): Define if needed. (__strtof128): Declare. (from_chars_impl): Handle _Float128. (from_chars): New _Float128 overload if USE_STRTOF128_FOR_FROM_CHARS is define. * src/c++17/floating_to_chars.cc (__strfromf128): Declare. (FLOAT128_TO_CHARS): Define even when _Float128 is supported and wider than long double. (F128_type): Use _Float128 for that case. (floating_type_traits): Specialize for F128_type rather than __float128. (sprintf_ld): Add length argument. Handle _Float128. (__floating_to_chars_shortest, __floating_to_chars_precision): Pass length to sprintf_ld. (to_chars): Add _Float128 overloads for the F128_type being _Float128 cases. * testsuite/20_util/to_chars/float128_c++23.cc: New test.
2022-11-06libstdc++: Declare const global variables inlinePatrick Palka5-23/+23
The changes inside the regex_constants and execution namespaces seem to be (the only) unimplemented parts of P0607R0 "Inline Variable for the Standard Library"; the rest of the changes are to implementation details. libstdc++-v3/ChangeLog: * include/bits/atomic_wait.h (_detail::__platform_wait_alignment): Declare inline. Remove redundant static specifier. (__detail::__atomic_spin_count_relax): Declare inline. (__detail::__atomic_spin_count): Likewise. * include/bits/regex_automaton.h (__detail::_S_invalid_state_id): Declare inline for C++17. Declare constexpr. Remove redundant const and static specifiers. * include/bits/regex_error.h (regex_constants::error_collate): Declare inline for C++17 as per P0607R0. (regex_constants::error_ctype): Likewise. (regex_constants::error_escape): Likewise. (regex_constants::error_backref): Likewise. (regex_constants::error_brack): Likewise. (regex_constants::error_paren): Likewise. (regex_constants::error_brace): Likewise. (regex_constants::error_badbrace): Likewise. (regex_constants::error_range): Likewise. (regex_constants::error_space): Likewise. (regex_constants::error_badrepeat): Likewise. (regex_constants::error_complexity): Likewise. (regex_constants::error_stack): Likewise. * include/ext/concurrence.h (__gnu_cxx::__default_lock_policy): Likewise. Remove redundant static specifier. * include/pstl/execution_defs.h (execution::seq): Declare inline for C++17 as per P0607R0. (execution::par): Likewise. (execution::par_unseq): Likewise. (execution::unseq): Likewise.
2022-11-06libstdc++: Move stream initialization into compiled library [PR44952]Patrick Palka1-0/+4
This patch moves the static object for constructing the standard streams out from <iostream> and into the compiled library on systems that support init priorities. This'll mean <iostream> no longer introduces a separate global constructor in each TU that includes it. We can do this only if the init_priority attribute is supported because we need a way to ensure the stream initialization runs first before any user global initializer, particularly when linking with a static libstdc++.a. PR libstdc++/44952 PR libstdc++/39796 PR libstdc++/98108 libstdc++-v3/ChangeLog: * include/std/iostream (__ioinit): No longer define here if the init_priority attribute is usable. * src/c++98/ios_init.cc (__ioinit): Define here instead if init_priority is usable, via ... * src/c++98/ios_base_init.h: ... this new file.
2022-11-05libstdc++: Do not use SFINAE for propagate_const conversions [PR107525]Jonathan Wakely1-22/+66
As the PR notes, the current conversion operators are defined as function templates so that we can use SFINAE. But this changes how they are considered for overload resolution. This moves those operators into base classes that can be specialized so the operators are obsent unless the constraints are satisfied. libstdc++-v3/ChangeLog: PR libstdc++/107525 * include/experimental/propagate_const (operator element_type*()): Move into base class that can be partially specilized to iompose constraints. (operator const element_type*()): Likewise. * testsuite/experimental/propagate_const/observers/107525.cc: New test.
2022-11-03libstdc++: Add missing move in ranges::copyJonathan Wakely1-1/+1
This is needed to support a move-only output iterator when the input iterators are specializations of __normal_iterator. libstdc++-v3/ChangeLog: * include/bits/ranges_algobase.h (__detail::__copy_or_move): Move output iterator. * testsuite/25_algorithms/copy/constrained.cc: Check copying to move-only output iterator.
2022-11-02libstdc++: Remove unnecessary variant member in std::expectedJonathan Wakely1-5/+4
Hui Xie pointed out that we don't need a dummy member in the union, because all constructors always initialize either _M_val or _M_unex. We still need the _M_void member of the expected<void, E> specialization, because the constructor has to initialize something when not using the _M_unex member. libstdc++-v3/ChangeLog: * include/std/expected (expected::_M_invalid): Remove.
2022-11-02libstdc++: Ignore -Wignored-qualifiers warning in <variant>Jonathan Wakely1-0/+3
The warning is wrong here, the qualifier serves a purpose and is not ignored (c.f. PR c++/107492). libstdc++-v3/ChangeLog: * include/std/variant (__variant::_Multi_array::__untag_result): Use pragma to suppress warning.
2022-11-01libstdc++: std::from_chars std::{,b}float16_t supportJakub Jelinek1-0/+42
The following patch adds std::from_chars support, similarly to the previous std::to_chars patch through APIs that use float instead of the 16-bit floating point formats as container. The patch uses the fast_float library and doesn't need any changes to it, like the previous patch it introduces wrapper classes around float that represent the float holding float16_t or bfloat16_t value, and specializes binary_format etc. from fast_float for these classes. The new test verifies exhaustively to_chars and from_chars afterward results in the original value (except for nans) in all the fmt cases. 2022-11-01 Jakub Jelinek <jakub@redhat.com> * include/std/charconv (__from_chars_float16_t, __from_chars_bfloat16_t): Declare. (from_chars): Add _Float16 and __gnu_cxx::__bfloat16_t overloads. * config/abi/pre/gnu.ver (GLIBCXX_3.4.31): Export _ZSt22__from_chars_float16_tPKcS0_RfSt12chars_format and _ZSt23__from_chars_bfloat16_tPKcS0_RfSt12chars_format. * src/c++17/floating_from_chars.cc (fast_float::floating_type_float16_t, fast_float::floating_type_bfloat16_t): New classes. (fast_float::binary_format<floating_type_float16_t>, fast_float::binary_format<floating_type_bfloat16_t>): New specializations. (fast_float::to_float<floating_type_float16_t>, fast_float::to_float<floating_type_bfloat16_t>, fast_float::to_extended<floating_type_float16_t>, fast_float::to_extended<floating_type_bfloat16_t>): Likewise. (fast_float::from_chars_16): New template function. (__floating_from_chars_hex): Allow instantiation with fast_float::floating_type_{,b}float16_t. (from_chars): Formatting fixes for float/double/long double overloads. (__from_chars_float16_t, __from_chars_bfloat16_t): New functions. * testsuite/20_util/to_chars/float16_c++23.cc: New test.
2022-11-01libstdc++: std::to_chars std::{,b}float16_t supportJakub Jelinek1-0/+44
The following patch on top of https://gcc.gnu.org/pipermail/libstdc++/2022-October/054849.html adds std::{,b}float16_t support for std::to_chars. When precision is specified (or for std::bfloat16_t for hex mode even if not), I believe we can just use the std::to_chars float (when float is mode compatible with std::float32_t) overloads, both formats are proper subsets of std::float32_t. Unfortunately when precision is not specified and we are supposed to emit shortest string, the std::{,b}float16_t strings are usually much shorter. E.g. 1.e7p-14f16 shortest fixed representation is 0.0001161 and shortest scientific representation is 1.161e-04 while 1.e7p-14f32 (same number promoted to std::float32_t) 0.00011610985 and 1.1610985e-04. Similarly for 1.38p-112bf16, 0.000000000000000000000000000000000235 2.35e-34 vs. 1.38p-112f32 0.00000000000000000000000000000000023472271 2.3472271e-34 For std::float16_t there are differences even in the shortest hex, say: 0.01p-14 vs. 1p-22 but only for denormal std::float16_t values (where all std::float16_t denormals converted to std::float32_t are normal), __FLT16_MIN__ and everything larger in absolute value than that is the same. Unless that is a bug and we should try to discover shorter representations even for denormals... std::bfloat16_t has the same exponent range as std::float32_t, so all std::bfloat16_t denormals are also std::float32_t denormals and thus the shortest hex representations are the same. As documented, ryu can handle arbitrary IEEE like floating point formats (probably not wider than IEEE quad) using the generic_128 handling, but ryu is hidden in libstdc++.so. As only few architectures support std::float16_t right now and some of them have special ISA requirements for those (e.g. on i?86 one needs -msse2) and std::bfloat16_t is right now supported only on x86 (again with -msse2), perhaps with aarch64/arm coming next if ARM is interested, but I think it is possible that more will be added later, instead of exporting APIs from the library to handle directly the std::{,b}float16_t overloads this patch instead exports functions which take a float which is a superset of those and expects the inline overloads to promote the 16-bit formats to 32-bit, then inside of the library it ensures they are printed right. With the added [[gnu::cold]] attribute because I think most users will primarily use these formats as storage formats and perform arithmetics in the excess precision for them and print also as std::float32_t the added support doesn't seem to be too large, on x86_64: readelf -Ws libstdc++.so.6.0.31 | grep float16_t 912: 00000000000ae824 950 FUNC GLOBAL DEFAULT 13 _ZSt21__to_chars_bfloat16_tPcS_fSt12chars_format@@GLIBCXX_3.4.31 5767: 00000000000ae4a1 899 FUNC GLOBAL DEFAULT 13 _ZSt20__to_chars_float16_tPcS_fSt12chars_format@@GLIBCXX_3.4.31 842: 000000000016d430 106 FUNC LOCAL DEFAULT 13 _ZN12_GLOBAL__N_113get_ieee_reprINS_23floating_type_float16_tEEENS_6ieee_tIT_EES3_ 865: 0000000000170980 1613 FUNC LOCAL DEFAULT 13 +_ZSt23__floating_to_chars_hexIN12_GLOBAL__N_123floating_type_float16_tEESt15to_chars_resultPcS3_T_St8optionalIiE.constprop.0.isra.0 7205: 00000000000ae824 950 FUNC GLOBAL DEFAULT 13 _ZSt21__to_chars_bfloat16_tPcS_fSt12chars_format 7985: 00000000000ae4a1 899 FUNC GLOBAL DEFAULT 13 _ZSt20__to_chars_float16_tPcS_fSt12chars_format so 3568 code bytes together or so. Tested with the attached test (which doesn't prove the shortest representation, just prints std::{,b}float16_t and std::float32_t shortest strings side by side, then tries to verify it can be emitted even into the exact sized range and can't be into range one smaller than that and tries to read what is printed back using from_chars float32_t overload (so there could be double rounding, but apparently there is none for the shortest strings). The only differences printed are for NaNs, where sNaNs are canonicalized to canonical qNaNs and as to_chars doesn't print NaN mantissa, even qNaNs other than the canonical one are read back just as the canonical NaN. Also attaching what Patrick wrote to generate the pow10_adjustment_tab, for std::float16_t only 1.0, 10.0, 100.0, 1000.0 and 10000.0 are powers of 10 in the range because __FLT16_MAX__ is 65504.0, and all of the above are exactly representable in std::float16_t, so we want to use 0 in pow10_adjustment_tab. 2022-11-01 Jakub Jelinek <jakub@redhat.com> * include/std/charconv (__to_chars_float16_t, __to_chars_bfloat16_t): Declare. (to_chars): Add _Float16 and __gnu_cxx::__bfloat16_t overloads. * config/abi/pre/gnu.ver (GLIBCXX_3.4.31): Export _ZSt20__to_chars_float16_tPcS_fSt12chars_format and _ZSt21__to_chars_bfloat16_tPcS_fSt12chars_format. * src/c++17/floating_to_chars.cc (floating_type_float16_t, floating_type_bfloat16_t): New types. (floating_type_traits<floating_type_float16_t>, floating_type_traits<floating_type_bfloat16_t>, get_ieee_repr<floating_type_float16_t>, get_ieee_repr<floating_type_bfloat16_t>, __handle_special_value<floating_type_float16_t>, __handle_special_value<floating_type_bfloat16_t>): New specializations. (floating_to_shortest_scientific): Handle floating_type_float16_t and floating_type_bfloat16_t like IEEE quad. (__floating_to_chars_shortest): For floating_type_bfloat16_t call __floating_to_chars_hex<float> rather than __floating_to_chars_hex<floating_type_bfloat16_t> to avoid instantiating the latter. (__to_chars_float16_t, __to_chars_bfloat16_t): New functions.
2022-11-01libstdc++-v3: Some std::*float*_t charconv and i/ostream overloadsJakub Jelinek3-0/+219
The following patch adds the easy part of <charconv>, <istream> and <ostream> changes for extended floats. In particular, for the first one only overloads where the _Float* has the same format as float/double/long double and for the latter two everything but the _GLIBCXX_HAVE_FLOAT128_MATH case. For charconv, I'm not really familiar with it, I'm pretty sure we need new libstdc++.so.6 side implementation of from_chars for {,b}float16_t and for to_chars not really sure but for unspecified precision if it should emit minimum characters that to_chars then can unambiguously parse, I think it is less than in the float case. For float128_t {to,from}_chars I think we even have it on the library side already, just ifdefed for powerpc64le only. For i/o stream operator<</>>, not sure what is better, if not providing anything at all, or doing what we in the end do if user doesn't override the virtual functions, or use {to,from}_chars under the hood, something else? Besides this, the patch adds some further missed // { dg-options "-std=gnu++2b" } spots, I've also noticed I got the formatting wrong in some testcases by not using spaces around VERIFY conditions and elsewhere by having space before ( for calls. The testsuite coverage is limited, I've added test for from_chars because it was easy to port, but not really sure what to do about to_chars, it has for float/double huge testcases which would be excessive to repeat. And for i/ostream not really sure what exactly is worth testing. 2022-11-01 Jakub Jelinek <jakub@redhat.com> * include/std/charconv (from_chars, to_chars): Add _Float{32,64,128} overloads for cases where those types match {float,double,long double}. * include/std/istream (basic_istream::operator>>): Add _Float{16,32,64,128} and __gnu_cxx::__bfloat16_t overloads. * include/std/ostream (basic_ostream::operator<<): Add _Float{16,32,64,128} and __gnu_cxx::__bfloat16_t overloads. * testsuite/20_util/from_chars/8.cc: New test. * testsuite/26_numerics/headers/cmath/nextafter_c++23.cc (test): Formatting fixes. * testsuite/26_numerics/headers/cmath/functions_std_c++23.cc: Add dg-options "-std=gnu++2b". (test_functions, main): Formatting fixes. * testsuite/26_numerics/headers/cmath/c99_classification_macros_c++23.cc: Add dg-options "-std=gnu++2b".
2022-10-31libstdc++-v3: <complex> support for extended floating point typesJakub Jelinek2-2/+684
The following patch adds <complex> support for extended floating point types. C++23 removes the float/double/long double specializations from the spec and instead adds explicit(bool) specifier on the converting constructor. The patch uses that for converting constructor of the base template as well as the float/double/long double specializations's converting constructors (e.g. so that it handles convertion construction also from complex of extended floating point types). Copy ctor was already defaulted as the spec now requires. The patch also adds partial specialization for the _Float{16,32,64,128} and __gnu_cxx::__bfloat16_t types because the base template doesn't use __complex__ but a pair of floating point values. The g++.dg/cpp23/ testcase verifies explicit(bool) works correctly. 2022-10-31 Jakub Jelinek <jakub@redhat.com> gcc/testsuite/ * g++.dg/cpp23/ext-floating12.C: New test. libstdc++-v3/ * include/std/complex (complex::complex converting ctor): For C++23 use explicit specifier with constant expression. Explicitly cast both parts to _Tp. (__complex_abs, __complex_arg, __complex_cos, __complex_cosh, __complex_exp, __complex_log, __complex_sin, __complex_sinh, __complex_sqrt, __complex_tan, __complex_tanh, __complex_pow): Add __complex__ _Float{16,32,64,128} and __complex__ decltype(0.0bf16) overloads. (complex<float>::complex converting ctor, complex<double>::complex converting ctor, complex<long double>::complex converting ctor): For C++23 implement as template with explicit specifier with constant expression and explicit casts. (__complex_type): New template. (complex): New partial specialization for types with extended floating point types. (__complex_acos, __complex_asin, __complex_atan, __complex_acosh, __complex_asinh, __complex_atanh): Add __complex__ _Float{16,32,64,128} and __complex__ decltype(0.0bf16) overloads. (__complex_proj): Likewise. Add template for complex of extended floating point types. * include/bits/cpp_type_traits.h (__is_floating): Specialize for _Float{16,32,64,128} and __gnu_cxx::__bfloat16_t. * testsuite/26_numerics/complex/ext_c++23.cc: New test.
2022-10-31libstdc++: Small extended float support tweaksJakub Jelinek1-2/+6
The following patch 1) enables the std::float128_t overloads for x86 with glibc 2.26+ 2) makes std::nextafter(std::float16_t, std::float16_t) and std::nextafter(std::bfloat16_t, std::bfloat16_t) constexpr 3) adds (small) testsuite coverage for that 2022-10-21 Jakub Jelinek <jakub@redhat.com> * config/os/gnu-linux/os_defines.h (_GLIBCXX_HAVE_FLOAT128_MATH): Uncomment. * include/c_global/cmath (nextafter(_Float16, _Float16)): Make it constexpr. If std::__is_constant_evaluated() call __builtin_nextafterf16. (nextafter(__gnu_cxx::__bfloat16_t, __gnu_cxx::__bfloat16_t)): Similarly but call __builtin_nextafterf16b. * testsuite/26_numerics/headers/cmath/nextafter_c++23.cc (test): Add static assertions to test constexpr nextafter.
2022-10-29libstdc++: Fix dangling reference in filesystem::path::filename()Jonathan Wakely1-3/+3
The new -Wdangling-reference warning noticed this. libstdc++-v3/ChangeLog: * include/bits/fs_path.h (path::filename()): Fix dangling reference.
2022-10-29libstdc++: Make placeholders inline when inline variables are availableArsen Arsenović1-29/+37
This slightly lowers the dependency of generated code on libstdc++.so. libstdc++-v3/ChangeLog: * include/std/functional: Make placeholders inline, if possible.
2022-10-29libstdc++: Don't use gstdint.h anymoreArsen Arsenović1-1/+0
libstdc++-v3/ChangeLog: * configure.ac: Stop generating gstdint.h. * src/c++11/compatibility-atomic-c++0x.cc: Stop using gstdint.h. * Makefile.in: Regenerate. * aclocal.m4: Regenerate. * config.h.in: Regenerate. * configure: Regenerate. * doc/Makefile.in: Regenerate. * include/Makefile.in: Regenerate. * libsupc++/Makefile.in: Regenerate. * po/Makefile.in: Regenerate. * python/Makefile.in: Regenerate. * src/Makefile.in: Regenerate. * src/c++11/Makefile.in: Regenerate. * src/c++17/Makefile.in: Regenerate. * src/c++20/Makefile.in: Regenerate. * src/c++98/Makefile.in: Regenerate. * src/filesystem/Makefile.in: Regenerate. * src/libbacktrace/Makefile.in: Regenerate. * testsuite/Makefile.in: Regenerate.
2022-10-28libstdc++: Fix allocator propagation in regex algorithms [PR107376]Jonathan Wakely2-9/+11
The PR points out that we assume the match_results allocator is default constuctible, which might not be true. We also have a related issue with unwanted propagation from an object that might have an unequal allocator. Ideally we use the same allocator type for _State_info::_M_match_queue but that would be an ABI change now. We should investigate if that can be done without breaking anything, which might be possible because the _Executor object is short-lived and never leaks out of the regex_match, regex_search, and regex_replace algorithms. If we change the mangled name for _Executor then there would be no ODR violations when mixing old and new definitions. This commit does not attempt that. libstdc++-v3/ChangeLog: PR libstdc++/107376 * include/bits/regex_executor.h (_Executor::_Executor): Use same allocator for _M_cur_results and _M_results. * include/bits/regex_executor.tcc (_Executor::_M_main_dispatch): Prevent possibly incorrect allocator propagating to _M_cur_results. * testsuite/28_regex/algorithms/regex_match/107376.cc: New test.
2022-10-26c++: Implement -Wdangling-reference [PR106393]Marek Polacek1-0/+3
This patch implements a new experimental warning (enabled by -Wall) to detect references bound to temporaries whose lifetime has ended. The primary motivation is the Note in <https://en.cppreference.com/w/cpp/algorithm/max>: Capturing the result of std::max by reference produces a dangling reference if one of the parameters is a temporary and that parameter is returned: int n = 1; const int& r = std::max(n-1, n+1); // r is dangling That's because both temporaries for n-1 and n+1 are destroyed at the end of the full expression. With this warning enabled, you'll get: g.C:3:12: warning: possibly dangling reference to a temporary [-Wdangling-reference] 3 | const int& r = std::max(n-1, n+1); | ^ g.C:3:24: note: the temporary was destroyed at the end of the full expression 'std::max<int>((n - 1), (n + 1))' 3 | const int& r = std::max(n-1, n+1); | ~~~~~~~~^~~~~~~~~~ The warning works by checking if a reference is initialized with a function that returns a reference, and at least one parameter of the function is a reference that is bound to a temporary. It assumes that such a function actually returns one of its arguments! (I added code to check_return_expr to suppress the warning when we've seen the definition of the function and we can say that it can return a variable with static storage duration.) It warns when the function in question is a member function, but only if the function is invoked on a temporary object, otherwise the warning would emit loads of warnings for valid code like obj.emplace<T>({0}, 0). It does detect the dangling reference in: struct S { const S& self () { return *this; } }; const S& s = S().self(); It warns in member initializer lists as well: const int& f(const int& i) { return i; } struct S { const int &r; S() : r(f(10)) { } }; I've run the testsuite/bootstrap with the warning enabled by default. There were just a few FAILs, all of which look like genuine bugs. A bootstrap with the warning enabled by default passed as well. When testing a previous version of the patch, there were many FAILs in libstdc++'s 22_locale/; all of them because the warning triggered on const test_type& obj = std::use_facet<test_type>(std::locale()); but this code looks valid -- std::use_facet doesn't return a reference to its parameter. Therefore I added a #pragma and code to suppress the warning. PR c++/106393 gcc/c-family/ChangeLog: * c.opt (Wdangling-reference): New. gcc/cp/ChangeLog: * call.cc (expr_represents_temporary_p): New, factored out of... (conv_binds_ref_to_temporary): ...here. Don't return false just because a ck_base is missing. Use expr_represents_temporary_p. (do_warn_dangling_reference): New. (maybe_warn_dangling_reference): New. (extend_ref_init_temps): Call maybe_warn_dangling_reference. * cp-tree.h: Adjust comment. * typeck.cc (check_return_expr): Suppress -Wdangling-reference warnings. gcc/ChangeLog: * doc/invoke.texi: Document -Wdangling-reference. libstdc++-v3/ChangeLog: * include/bits/locale_classes.tcc: Add #pragma to disable -Wdangling-reference with std::use_facet. gcc/testsuite/ChangeLog: * g++.dg/cpp23/elision4.C: Use -Wdangling-reference, add dg-warning. * g++.dg/cpp23/elision7.C: Likewise. * g++.dg/warn/Wdangling-pointer-2.C: Use -Wno-dangling-reference. * g++.dg/warn/Wdangling-reference1.C: New test. * g++.dg/warn/Wdangling-reference2.C: New test. * g++.dg/warn/Wdangling-reference3.C: New test.
2022-10-21libstdc++: Fix std::move_only_function for incomplete parameter typesJonathan Wakely1-4/+1
The std::move_only_function::__param_t alias template attempts to optimize argument passing for the invoker, by passing by rvalue reference for types that are non-trivial or large. However, the precondition for is_trivally_copyable makes it unsuitable for using here, and can cause ODR violations. Just use is_scalar instead, and pass all class types (even small, trivial ones) by value. libstdc++-v3/ChangeLog: * include/bits/mofunc_impl.h (move_only_function::__param_t): Use __is_scalar instead of is_trivially_copyable. * testsuite/20_util/move_only_function/call.cc: Check parameters involving incomplete types.
2022-10-20libstdc++: Redefine __from_chars_alnum_to_val's tablePatrick Palka1-31/+28
After the C++23 constexpr <charconv> patch r13-3313-g378a0f1840e694 we have some modules testsuite regressions: FAIL: g++.dg/modules/xtreme-header-4_b.C -std=c++2b (test for excess errors) FAIL: g++.dg/modules/xtreme-header_b.C -std=c++2b (test for excess errors) Like with PR105297, the cause seems to be the deduced type of __table resolving ahead of time to a local class type, which trips up modules. And unfortunately that PR's minimal workaround of making __tables's initializer value dependent doesn't help in this case. So this patch works around this by avoiding using a local class for the table type. And I suppose we should use a static data member to define the table once for all dialects (including C++14) instead of having to define it twice in C++23 mode (once as a static local variable and again as a variable template for sake of constexpr evaluation). libstdc++-v3/ChangeLog: * include/std/charconv (__detail::__from_chars_alnum_to_val_table): Redefine as a class template containing the members type, value and _S_make_table. Don't use a local class as the table type. (__detail::__table): Remove. (__detail::__from_chars_alnum_to_val): Adjust after the above.
2022-10-19libstdc++: Implement remaining P2474R2 changes to views::take/dropPatrick Palka1-0/+56
libstdc++-v3/ChangeLog: * include/std/ranges (views::__detail::__is_repeat_view): Define and later define a partial specialization. (views::__detail::__take_of_repeat_view): Declare and later define. (views::__detail::__drop_of_repeat_view): Likewise. (views::_Take::operator()): Return a repeat_view if the argument is a repeat_view as per P2474R2. (views::_Drop::operator()): Likewise. (repeat_view): Befriend __take/drop_of_repeat_view. * testsuite/std/ranges/repeat/1.cc (test04): New test.
2022-10-19libstdc++: Fix typo in stride_view's operator- [PR107313]Patrick Palka1-1/+1
PR libstdc++/107313 libstdc++-v3/ChangeLog: * include/std/ranges (stride_view::_Iterator::operator-): Fix typo. * testsuite/std/ranges/adaptors/stride/1.cc (test03): New test.
2022-10-19libstdc++-v3: Implement {,b}float16_t nextafter and some fixes [PR106652]Jakub Jelinek2-6/+95
The following patch implements nextafter for std::{,b}float16_t, though right now only without constexpr support, and adds a testcase for it. The testcase unfortunately relevealed I've screwed up testing of my last patch. I've tested earlier version of the patch with --target_board=unix/-std=c++23 but didn't test the final version with that RUNTESTFLAGS, so missed an invalid call to std::sph_neumann (too many arguments) in the test. And, I've made a typo in the guard for numeric_limits (the reason for the guard is I wanted to avoid defining a large macro that nothing will then use because the std::{,b}float*_t types are C++23 only) and so numeric_limits wasn't specialized for the types at all but testsuite/18_support/headers/limits/synopsis_cxx23.cc test didn't detect that. In the nextafter implementation I'm calling __builtin_nextafterf to get various required side-effects for nextafter from 0/-0, or from max to inf or from min to largest subnormal to avoid needing to set errno inline, or use inline asm specific for each processor to force math evaluation barriers. Dunno if #ifdef __INT16_TYPE__ using __float16_int_type = __INT16_TYPE__; #else using __float16_int_type = short int; #endif isn't too ugly, perhaps we could just blindly use short int and hope or even assert it has the same size as _Float16 or __gnu_cxx::__bfloat16_t? Only aarch64, arm, csky, gcn, x86, nvptx and riscv support these types and all of them have 16-bit short (I think the only target with some other short size is avr with certain command line switches where both short and int are 8-bit, but such mode isn't compatible with C and C++ requirements). 2022-10-19 Jakub Jelinek <jakub@redhat.com> PR c++/106652 * include/std/limits: Fix a typo, 202202L -> 202002L. (numeric_limits::<_Float16>::radix, numeric_limits::<_Float32>::radix, numeric_limits::<_Float64>::radix, numeric_limits::<_Float128>::radix, numeric_limits::<__gnu_cxx::__bfloat16_t>::radix): Use __FLT_RADIX__ macro instead of type specific macros. * include/c_global/cmath (nextafter(_Float16, _Float16)): New overload. (nextafter(__gnu_cxx::__bfloat16_t, __gnu_cxx::__bfloat16_t)): Likewise. * testsuite/26_numerics/headers/cmath/functions_std_c++23.cc (test_functions): Uncomment nextafter test. Fix up sph_neumann call. * testsuite/26_numerics/headers/cmath/nextafter_c++23.cc: New test.
2022-10-18libstdc++: Implement ranges::stride_view from P1899R3Patrick Palka1-0/+351
libstdc++-v3/ChangeLog: * include/std/ranges (stride_view): Define. (stride_view::_Iterator): Define. (views::__detail::__can_stride_view): Define. (views::_Stride, views::stride): Define. * testsuite/std/ranges/adaptors/stride/1.cc: New test.
2022-10-18libstdc++: Partial library support for std::float{16,32,64,128}_t and ↵Jakub Jelinek12-63/+2216
std::bfloat16_t The following patch is partial support for std::float{16,32,64,128}_t and std::bfloat16_t in libstdc++. https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1467r9.html says that <ostream>, <istream>, <charconv> and <complex> need changes toom, but that isn't implemented so far. In <cmath> the only thing missing I'm aware of is std::nextafter std::float16_t and std::bfloat16_t overloads (I think we probably need to implement that out of line somewhere, or inline? - might need inline asm barriers) and std::nexttoward overloads (those are intentional, you said there is a LWG issue about that). Also, this patch has the glibc 2.26+ std::float128_t support for platforms where long double isn't IEEE quad format temporarily disabled because it depends on https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603665.html changes which aren't in yet. The patch also doesn't include any testcases to cover the <type_traits> changes, it isn't clear to me where to put that. 2022-10-18 Jakub Jelinek <jakub@redhat.com> PR c++/106652 * include/std/stdfloat: New file. * include/std/numbers (__glibcxx_numbers): Define and use it for __float128 explicit instantiations as well as _Float{16,32,64,128} and __gnu_cxx::__bfloat16_t. * include/std/atomic (atomic<_Float16>, atomic<_Float32>, atomic<_Float64>, atomic<_Float128>, atomic<__gnu_cxx::__bfloat16_t>): New explicit instantiations. * include/std/type_traits (__is_floating_point_helper<_Float16>, __is_floating_point_helper<_Float32>, __is_floating_point_helper<_Float64>, __is_floating_point_helper<_Float128>, __is_floating_point_helper<__gnu_cxx::__bfloat16_t>): Likewise. * include/std/limits (__glibcxx_concat3_, __glibcxx_concat3, __glibcxx_float_n): Define. (numeric_limits<_Float16>, numeric_limits<_Float32>, numeric_limits<_Float64>, numeric_limits<_Float128>, numeric_limits<__gnu_cxx::__bfloat16_t>): New explicit instantiations. * include/bits/std_abs.h (abs): New overloads for _Float{16,32,64,128} and __gnu_cxx::__bfloat16_t. * include/bits/c++config (_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128): Define if long double is IEEE quad. (__gnu_cxx::__bfloat16_t): New using. * include/c_global/cmath (acos, asin, atan, atan2, ceil, cos, cosh, exp, fabs, floor, fmod, frexp, ldexp, log, log10, modf, pow, sin, sinh, sqrt, tan, tanh, fpclassify, isfinite, isinf, isnan, isnormal, signbit, isgreater, isgreaterequal, isless, islessequal, islessgreater, isunordered, acosh, asinh, atanh, cbrt, copysign, erf, erfc, exp2, expm1, fdim, fma, fmax, fmin, hypot, ilogb, lgamma, llrint, llround, log1p, log2, logb, lrint, lround, nearbyint, nextafter, remainder, rint, round, scalbln, scalbn, tgamma, trunc, lerp): New overloads with _Float{16,32,64,128} or __gnu_cxx::__bfloat16_t types. * config/os/gnu-linux/os_defines.h (_GLIBCXX_HAVE_FLOAT128_MATH): Prepare for definition if glibc 2.26 and later implements *f128 APIs but comment out the actual definition for now. * include/ext/type_traits.h (__promote<_Float16>, __promote<_Float32>, __promote<_Float64>, __promote<_Float128>, __promote<__gnu_cxx::__bfloat16_t>): New specializations. * include/Makefile.am (std_headers): Add stdfloat. * include/Makefile.in: Regenerated. * include/precompiled/stdc++.h: Include stdfloat. * testsuite/18_support/headers/stdfloat/types_std.cc: New test. * testsuite/18_support/headers/limits/synopsis_cxx23.cc: New test. * testsuite/26_numerics/headers/cmath/c99_classification_macros_c++23.cc: New test. * testsuite/26_numerics/headers/cmath/functions_std_c++23.cc: New test. * testsuite/26_numerics/numbers/4.cc: New test. * testsuite/29_atomics/atomic_float/requirements_cxx23.cc: New test.
2022-10-17libstdc++: Fix value of __cpp_lib_constexpr_charconvJonathan Wakely2-2/+2
libstdc++-v3/ChangeLog: * include/std/charconv (__cpp_lib_constexpr_charconv): Define to correct value. * include/std/version (__cpp_lib_constexpr_charconv): Likewise. * testsuite/20_util/to_chars/constexpr.cc: Check correct value. * testsuite/20_util/to_chars/version.cc: Likewise.
2022-10-15libstdc++: Implement constexpr std::to_chars for C++23 (P2291R3)Jonathan Wakely3-16/+30
Some of the helper functions use static constexpr local variables, which is not permitted in a core constant expression. Removing the 'static' seems to have negligible performance effect for __to_chars and __to_chars_16. For __from_chars_alnum_to_val removing the 'static' causes a significant performance impact for base 36 conversions. Use a consteval lambda instead. libstdc++-v3/ChangeLog: * include/bits/charconv.h (__to_chars_10_impl): Add constexpr for C++23. Remove 'static' from array. * include/std/charconv (__cpp_lib_constexpr_charconv): Define. (__to_chars, __to_chars_16): Remove 'static' from array, add constexpr. (__to_chars_10, __to_chars_8, __to_chars_2, __to_chars_i) (to_chars, __raise_and_add, __from_chars_pow2_base) (__from_chars_alnum, from_chars): Add constexpr. (__from_chars_alnum_to_val): Avoid local static during constant evaluation. Add constexpr. * include/std/version (__cpp_lib_constexpr_charconv): Define. * testsuite/20_util/from_chars/constexpr.cc: New test. * testsuite/20_util/to_chars/constexpr.cc: New test. * testsuite/20_util/to_chars/version.cc: New test.
2022-10-15libstdc++: Fix uses_allocator_construction args for cv pair (LWG 3677)Jonathan Wakely3-5/+2
The _Std_pair concept uses in <bits/uses_allocator_args.h> handles const qualified pairs, but not volatile qualified. That's because it just uses __is_pair which is specialized for const pairs. This removes the partial specialization __is_pair<const pair<T,U>>, so that __is_pair is now only true for cv-unqualified pairs. Then _Std_pair needs to explicitly use remove_cv_t for the argument to __is_pair. The other use of __is_pair is in map::insert(Pair&&) which doesn't want to handle volatile so should just use remove_const_t. libstdc++-v3/ChangeLog: * include/bits/stl_map.h (map::insert(Pair&&)): Use remove_const_t on argument to __is_pair. * include/bits/stl_pair.h (__is_pair<const pair<T,U>>): Remove partial specialization. * include/bits/uses_allocator_args.h (_Std_pair): Use remove_cv_t as per LWG 3677. * testsuite/20_util/uses_allocator/lwg3677.cc: New test.
2022-10-14libstdc++: Use markdown in Doxygen commentJonathan Wakely1-3/+3
This makes the comment easier to read in the source, without altering the Doxygen output. libstdc++-v3/ChangeLog: * include/std/iostream: Use markdown in Doxygen comment.
2022-10-12libstdc++: Add __gnu_debug::basic_string<>::compare overloadsFrançois Dumont1-14/+5
Rather than adding those implementations we are adding a: using _Base::compare; so that any compare method not implemented at __gnu_debug::basic_string level are injected from the base class. Also review how __gnu_debug::basic_string is tested. Now require to define _GLIBCXX_TEST_DEBUG_STRING when running 'make check-debug'. libstdc++-v3/ChangeLog * include/debug/string: Add using _Base::compare. (__gnu_debug::basic_string<>::compare(const basic_string<>&)): Remove. (__gnu_debug::basic_string<>::compare(size_type, size_type, const basic_string<>&)): Remove. (__gnu_debug::basic_string<>::compare(size_type, size_type, const basic_string<>&, size_type, size_type)): Remove. * testsuite/util/testsuite_string.h [_GLIBCXX_TEST_DEBUG_STRING]: Include <debug/string>. * testsuite/21_strings/basic_string/operations/compare/char/1.cc: Include testsuite_string.h and use __gnu_test::string. * testsuite/21_strings/basic_string/operations/compare/char/13650.cc: Likewise. * testsuite/21_strings/basic_string/operations/compare/char/2.cc: Likewise. * testsuite/21_strings/basic_string/operations/rfind/char/1.cc: Likewise. * testsuite/21_strings/basic_string/operations/rfind/char/2.cc: Likewise. * testsuite/21_strings/basic_string/operations/rfind/char/3.cc: Likewise. * testsuite/21_strings/basic_string/operations/compare/wchar_t/1.cc: Include testsuite_string.h and use __gnu_test::wstring. * testsuite/21_strings/basic_string/operations/compare/wchar_t/13650.cc: Likewise. * testsuite/21_strings/basic_string/operations/compare/wchar_t/2.cc: Likewise.
2022-10-12libstdc++: Implement ranges::repeat_view from P2474R2Patrick Palka1-0/+210
libstdc++-v3/ChangeLog: * include/std/ranges (repeat_view): Define. (repeat_view::_Iterator): Define. (views::__detail::__can_repeat_view): Define. (views::__detail::__can_bounded_repeat_view): Define. (views::_Repeat, views::repeat): Define. * testsuite/std/ranges/repeat/1.cc: New test.
2022-10-11libstdc++: Allow emergency EH alloc pool size to be tuned [PR68606]Jonathan Wakely1-0/+1
Implement a long-standing request to support tuning the size of the emergency buffer for allocating exceptions after malloc fails, or to disable that buffer entirely. It's now possible to disable the dynamic allocation of the buffer and use a fixed-size static buffer, via --enable-libstdcxx-static-eh-pool. This is a built-time choice that is baked into libstdc++ and so affects all code linked against that build of libstdc++. The size of the pool can be set by --with-libstdcxx-eh-pool-obj-count=N which is measured in units of sizeof(void*) not bytes. A given exception type such as std::system_error depends on the target, so giving a size in bytes wouldn't be portable across 16/32/64-bit targets. When libstdc++ is configured to use a dynamic buffer, the size of that buffer can now be tuned at runtime by setting the GLIBCXX_TUNABLES environment variable (c.f. PR libstdc++/88264). The number of exceptions to reserve space for is controlled by the "glibcxx.eh_pool.obj_count" and "glibcxx.eh_pool.obj_size" tunables. The pool will be sized to be able to allocate obj_count exceptions of size obj_size*sizeof(void*) and obj_count "dependent" exceptions rethrown by std::rethrow_exception. With the ability to tune the buffer size, we can reduce the default pool size on 32-bit and 16-bit targets. Most users never need to throw 1kB exceptions in parallel from hundreds of threads after malloc is OOM. The users who do need that can use the tunables to select larger sizes. The old defaults can be chosen at runtime by setting GLIBCXX_TUNABLES to: 64-bit: glibcxx.eh_pool.obj_count=64:glibcxx.eh_pool.obj_size=112 32-bit: glibcxx.eh_pool.obj_count=32:glibcxx.eh_pool.obj_size=104 Or approximated by configuring with: 64-bit: --with-libstdcxx-eh-pool-obj-count=252 32-bit: --with-libstdcxx-eh-pool-obj-count=94 libstdc++-v3/ChangeLog: PR libstdc++/68606 * Makefile.in: Regenerate. * acinclude.m4 (GLIBCXX_EMERGENCY_EH_ALLOC): New macro. * configure: Regenerate. * configure.ac: Use GLIBCXX_EMERGENCY_EH_ALLOC. * crossconfig.m4: Check for secure_getenv. * doc/Makefile.in: Regenerate. * doc/xml/manual/configure.xml: Document new configure options. * doc/xml/manual/evolution.xml: Document addition of tunables. * doc/xml/manual/using_exceptions.xml: Document emergency buffer and tunables. * doc/html/*: Regenerate. * include/Makefile.in: Regenerate. * libsupc++/Makefile.am: Use EH_POOL_FLAGS. * libsupc++/Makefile.in: Regenerate. * libsupc++/eh_alloc.cc (EMERGENCY_OBJ_SIZE): Define in units of sizeof(void*) not including the ABI's exception header. (EMERGENCY_OBJ_COUNT): Define as target-independent calculation based on word size. (MAX_OBJ_COUNT): Define macro for upper limit on pool size. (pool) [_GLIBCXX_EH_POOL_STATIC]: Use fixed-size buffer. (pool::buffer_size_in_bytes): New static member function. (pool::pool): Parse GLIBCXX_TUNABLES environment variable to set pool size at runtime. (pool::in_pool): Use std::less<void*> for total order. (__freeres) [_GLIBCXX_EH_POOL_STATIC]: Do nothing. (__cxa_free_exception, __cxa_free_dependent_exception): Add [[unlikely]] attributes. * po/Makefile.in: Regenerate. * python/Makefile.in: Regenerate. * src/Makefile.in: Regenerate. * src/c++11/Makefile.in: Regenerate. * src/c++17/Makefile.in: Regenerate. * src/c++20/Makefile.in: Regenerate. * src/c++98/Makefile.in: Regenerate. * src/filesystem/Makefile.in: Regenerate. * src/libbacktrace/Makefile.in: Regenerate. * testsuite/Makefile.in: Regenerate.
2022-10-10libstdc++: Revert addition of constraints to make_signed/make_unsignedJonathan Wakely1-6/+0
Constraining the primary template makes it unusable in uninstantiated contexts. libstdc++-v3/ChangeLog: * include/std/type_traits (make_signed, make_unsigned): Remove constraints on primary template. * testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Undo changes to expected error in C++20 mode. * testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Likewise. * testsuite/24_iterators/range_access/range_access_cpp20_neg.cc: Likewise. * testsuite/20_util/make_signed/requirements/uninstantiated.cc: New test. * testsuite/20_util/make_unsigned/requirements/uninstantiated.cc: New test.
2022-10-10libstdc++: std::make_signed_t<cv bool> should be ill-formedJonathan Wakely1-4/+14
Currently we only reject std::make_signed_t<bool> but not cv bool. Similarly for std::make_unsigned_t<cv bool>. As well as making those ill-formed, this adds a requires-clause to the make_signed and make_unsigned primary templates. This makes non-integral, non-enum cases fail immediately with a clear error, rather than giving an error about __make_signed_selector<T, false, false> being incomplete. libstdc++-v3/ChangeLog: * include/std/type_traits (make_signed, make_unsigned): Add specializations for cv bool. Add requires-clause for C++20 to improve diagnostics for non-integral, non-enum cases. * testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Check cv bool. * testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Likewise. * testsuite/24_iterators/range_access/range_access_cpp20_neg.cc: Adjust expected errors for C++20 and later. * testsuite/lib/prune.exp: Prune "in requirements [with ...]" lines from diagnostics.
2022-10-07libstdc++: Shuffle header dependencies of <functional>Jonathan Wakely2-9/+8
The <new> header is needed by std::function to use placement new, so include it in <bits/std_function.h> instead of in <functional>. libstdc++-v3/ChangeLog: * include/bits/std_function.h: Include <new> but do not include <bits/stl_function.h>. * include/std/functional: Do not include <new>.
2022-10-05libtdc++: Regenerate Makefile.in after freestanding header changesJonathan Wakely1-52/+49
libstdc++-v3/ChangeLog: * include/Makefile.in: Regenerate.
2022-10-05libstdc++: Guard use of new built-in with __has_builtinJonathan Wakely1-0/+2
Another case where I forgot that non-GCC compilers don't have this built-in yet. libstdc++-v3/ChangeLog: * include/bits/invoke.h (__invoke_r): Check __has_builtin(__reference_converts_from_temporary) before using built-in.
2022-10-04libstdc++: Use new built-ins __remove_cv, __remove_reference etc.Jonathan Wakely1-9/+24
libstdc++-v3/ChangeLog: * include/std/type_traits (remove_cv): Use __remove_cv built-in. (remove_reference): Use __remove_reference built-in. (remove_cvref): Use __remove_cvref built-in. Remove inheritance for fallback implementation.
2022-10-04libstdc++: Refactor seed sequence constraints in <random>Jonathan Wakely2-18/+27
Every use of _If_seed_seq in <random> and <ext/random> uses it with enable_if. We can just move the enable_if into the helper alias instead of repeating it everywhere. libstdc++-v3/ChangeLog: * include/bits/random.h (__is_seed_seq): Replace with ... (_If_seed_seq_for): ... this. * include/ext/random: Adjust to use _If_seed_seq_for.
2022-10-04libstdc++: Avoid heavyweight std::visit in ranges::join_with_viewPatrick Palka1-11/+36
libstdc++-v3/ChangeLog: * include/std/ranges (join_with_view::_Iterator::operator*): Replace use of std::visit with manual visitation. (join_with_view::_Iterator::operator++): Likewise. (join_with_view::_Iterator::operator--): Likewise. (join_with_view::_Iterator::iter_move): Likewise. (join_with_view::_Iterator::iter_swap): Likewise.
2022-10-04libstdc++: Enable std::hash<coroutine_handle<P>> [PR107139]Jonathan Wakely1-8/+2
Everything that <coroutine> depends on is available for freestanding now. libstdc++-v3/ChangeLog: PR libstdc++/107139 * include/std/coroutine: Remove all _GLIBCXXHOSTED preprocessor conditionals.
2022-10-04libstdc++: Make <cstdint> work freestanding [PR107134]Jonathan Wakely1-2/+57
When gcc/config.gcc defines use_gcc_stdin=wrap, GCC's <stdint.h> tries to use libc's <stdint.h> unless -ffreestanding is used. When libstdc++ is configured --disable-hosted-libstdcxx we want <cstdint> to work even without -ffreestanding being given. This is a kluge to make it include GCC's <stdint-gcc.h> directly even without -ffreestanding. libstdc++-v3/ChangeLog: PR libstdc++/107134 * include/c_global/cstdint [!_GLIBCXX_HOSTED]: Include <stdint-gcc.h> directly.
2022-10-04libstdc++: Define <bits/functexcept.h> functions for freestanding [PR107135]Jonathan Wakely2-7/+26
We don't compile src/c++11/functexcept.cc for freestanding, so just define the functions used by freestanding entities as inline calls to std::terminate. libstdc++-v3/ChangeLog: PR libstdc++/107135 * include/bits/functexcept.h [!_GLIBCXX_HOSTED] (__throw_invalid_argument, __throw_out_of_range) (__throw_out_of_range_fmt, __throw_runtime_error) (__throw_overflow_error): Define inline. * include/std/bitset (_M_copy_from_ptr) [!_GLIBCXX_HOSTED]: Replace __builtin_abort with __throw_invalid_argument.
2022-10-04libstdc++: Implement ranges::join_with_view from P2441R2Patrick Palka1-0/+458
libstdc++-v3/ChangeLog: * include/std/ranges: Include <variant> for C++23. (__detail::__compatible_joinable_ranges): Define. (__detail::__bidirectional_common): Define. (join_with_view): Define. (join_with_view::_Iterator): Define. (join_with_view::_Sentinel): Define. (views::__detail::__can_join_with_view): Define. (views::_JoinWith, views::join_with): Define. * testsuite/std/ranges/adaptors/join_with/1.cc: New test.
2022-10-04libstdc++: Use ///< for inline documentationArsen Arsenović3-14/+14
I noticed that some variables were misdocumented when using trailing comment for documentation. I ran a search with a relatively simple regex[1] to look for any ///s following some code that did not have a <, and came up with these instances only. [1]: \s*([^ ]+\s*)+///[^<].*$ libstdc++-v3/ChangeLog: * include/std/iostream: Use ///< for inline documentation. * include/std/limits: Likewise. * include/experimental/internet: Likewise.
2022-10-03libstdc++: Enable std::bitset<N>::bitset(const char*) for freestandingJonathan Wakely1-12/+50
The std::bitset constructor from a character string is specified in terms of std::basic_string and std::char_traits, but doesn't need to be. This makes it available for freestanding. libstdc++-v3/ChangeLog: * include/std/bitset (bitset(const C*, size_type n, C, C)) [!_GLIBCXX_HOSTED]: Remove std::basic_string dependency. (_M_copy_from_ptr) [!_GLIBCXX_HOSTED]: Abort instead of throwing.
2022-10-03libstdc++: Re-enable std::hash<std::bitset> in freestanding [PR103626]Arsen Arsenović1-4/+5
PR libstdc++/103626 - _GLIBCXX_HOSTED should respect -ffreestanding libstdc++-v3/ChangeLog: PR libstdc++/103626 * include/std/bitset [!_GLIBCXX_HOSTED]: Re-enable std::hash. * testsuite/20_util/bitset/cons/constexpr_c++23.cc: Require ET hosted. * testsuite/20_util/bitset/ext/constexpr.cc: Likewise.
2022-10-03libstdc++: Rework how freestanding install works [PR106953]Arsen Arsenović2-479/+477
In light of there being far more freestanding headers now, ad-hoc maintenance of a subset of the install implementation has become unsustainable. Instead, we gate off a part of the normal install routine so that it works without HOSTED enabled, as well as subdivide lists of headers into freestanding and hosted components, according to the HOSTED flag. libstdc++-v3/ChangeLog: PR libstdc++/106953 * include/Makefile.am [!_GLIBCXX_HOSTED]: Remove install-freestanding-headers, unifying it with the usual install-headers * include/Makefile.in: Regenerate.
2022-10-03libstdc++: Mark headers that must be hosted as such [PR103626]Arsen Arsenović169-59/+424
PR libstdc++/103626 - _GLIBCXX_HOSTED should respect -ffreestanding Co-authored-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: PR libstdc++/103626 * include/Makefile.am: Add new header. * include/Makefile.in: Regenerate. * include/bits/requires_hosted.h: New header. * include/experimental/algorithm: Include <bits/requires_hosted.h>. * include/experimental/any: Likewise. * include/experimental/array: Likewise. * include/experimental/buffer: Likewise. * include/experimental/chrono: Likewise. * include/experimental/deque: Likewise. * include/experimental/executor: Likewise. * include/experimental/filesystem: Likewise. * include/experimental/forward_list: Likewise. * include/experimental/functional: Likewise. * include/experimental/internet: Likewise. * include/experimental/io_context: Likewise. * include/experimental/iterator: Likewise. * include/experimental/list: Likewise. * include/experimental/map: Likewise. * include/experimental/memory: Likewise. * include/experimental/memory_resource: Likewise. * include/experimental/net: Likewise. * include/experimental/netfwd: Likewise. * include/experimental/numeric: Likewise. * include/experimental/optional: Likewise. * include/experimental/propagate_const: Likewise. * include/experimental/random: Likewise. * include/experimental/ratio: Likewise. * include/experimental/regex: Likewise. * include/experimental/scope: Likewise. * include/experimental/set: Likewise. * include/experimental/simd: Likewise. * include/experimental/socket: Likewise. * include/experimental/source_location: Likewise. * include/experimental/string: Likewise. * include/experimental/string_view: Likewise. * include/experimental/system_error: Likewise. * include/experimental/timer: Likewise. * include/experimental/tuple: Likewise. * include/experimental/unordered_map: Likewise. * include/experimental/unordered_set: Likewise. * include/experimental/utility: Likewise. * include/experimental/vector: Likewise. * include/std/barrier: Likewise. * include/std/chrono: Likewise. * include/std/condition_variable: Likewise. * include/std/deque: Likewise. * include/std/execution: Likewise. * include/std/filesystem: Likewise. * include/std/forward_list: Likewise. * include/std/fstream: Likewise. * include/std/future: Likewise. * include/std/iomanip: Likewise. * include/std/ios: Likewise. * include/std/iosfwd: Likewise. * include/std/iostream: Likewise. * include/std/istream: Likewise. * include/std/latch: Likewise. * include/std/list: Likewise. * include/std/locale: Likewise. * include/std/map: Likewise. * include/std/memory_resource: Likewise. * include/std/mutex: Likewise. * include/std/ostream: Likewise. * include/std/queue: Likewise. * include/std/random: Likewise. * include/std/regex: Likewise. * include/std/semaphore: Likewise. * include/std/set: Likewise. * include/std/shared_mutex: Likewise. * include/std/spanstream: Likewise. * include/std/sstream: Likewise. * include/std/stack: Likewise. * include/std/stacktrace: Likewise. * include/std/stop_token: Likewise. * include/std/streambuf: Likewise. * include/std/string: Likewise. * include/std/syncstream: Likewise. * include/std/system_error: Likewise. * include/std/thread: Likewise. * include/std/unordered_map: Likewise. * include/std/unordered_set: Likewise. * include/std/valarray: Likewise. * include/std/vector: Likewise. * include/tr1/array: Likewise. * include/tr1/ccomplex: Likewise. * include/tr1/cctype: Likewise. * include/tr1/cfenv: Likewise. * include/tr1/cfloat: Likewise. * include/tr1/cinttypes: Likewise. * include/tr1/climits: Likewise. * include/tr1/cmath: Likewise. * include/tr1/complex: Likewise. * include/tr1/complex.h: Likewise. * include/tr1/cstdarg: Likewise. * include/tr1/cstdbool: Likewise. * include/tr1/cstdint: Likewise. * include/tr1/cstdio: Likewise. * include/tr1/cstdlib: Likewise. * include/tr1/ctgmath: Likewise. * include/tr1/ctime: Likewise. * include/tr1/ctype.h: Likewise. * include/tr1/cwchar: Likewise. * include/tr1/cwctype: Likewise. * include/tr1/fenv.h: Likewise. * include/tr1/float.h: Likewise. * include/tr1/functional: Likewise. * include/tr1/inttypes.h: Likewise. * include/tr1/limits.h: Likewise. * include/tr1/math.h: Likewise. * include/tr1/memory: Likewise. * include/tr1/random: Likewise. * include/tr1/regex: Likewise. * include/tr1/stdarg.h: Likewise. * include/tr1/stdbool.h: Likewise. * include/tr1/stdint.h: Likewise. * include/tr1/stdio.h: Likewise. * include/tr1/stdlib.h: Likewise. * include/tr1/tgmath.h: Likewise. * include/tr1/tuple: Likewise. * include/tr1/type_traits: Likewise. * include/tr1/unordered_map: Likewise. * include/tr1/unordered_set: Likewise. * include/tr1/utility: Likewise. * include/tr1/wchar.h: Likewise. * include/tr1/wctype.h: Likewise. * include/c_global/cmath: Likewise. * include/ext/algorithm: Include <bits/requires_hosted.h>. * include/ext/bitmap_allocator.h: Likewise. * include/ext/cmath: Likewise. * include/ext/codecvt_specializations.h: Likewise. * include/ext/debug_allocator.h: Likewise. * include/ext/enc_filebuf.h: Likewise. * include/ext/extptr_allocator.h: Likewise. * include/ext/functional: Likewise. * include/ext/malloc_allocator.h: Likewise. * include/ext/memory: Likewise. * include/ext/mt_allocator.h: Likewise. * include/ext/new_allocator.h: Likewise. * include/ext/numeric: Likewise. * include/ext/pod_char_traits.h: Likewise. * include/ext/pool_allocator.h: Likewise. * include/ext/random: Likewise. * include/ext/random.tcc: Likewise. * include/ext/rb_tree: Likewise. * include/ext/rc_string_base.h: Likewise. * include/ext/rope: Likewise. * include/ext/ropeimpl.h: Likewise. * include/ext/slist: Likewise. * include/ext/sso_string_base.h: Likewise. * include/ext/stdio_filebuf.h: Likewise. * include/ext/stdio_sync_filebuf.h: Likewise. * include/ext/string_conversions.h: Likewise. * include/ext/throw_allocator.h: Likewise. * include/ext/vstring.h: Likewise. * include/ext/vstring.tcc: Likewise. * include/ext/vstring_fwd.h: Likewise. * include/ext/vstring_util.h: Likewise. * include/std/charconv: Likewise. (__cpp_lib_to_chars): Do not define for freestanding. * include/std/version: Adjust which macros get defined in freestanding. * include/ext/pointer.h [!_GLIBCXX_HOSTED]: Omit iostream functionality from freestanding. * include/std/algorithm [!_GLIBCXX_HOSTED]: Omit PSTL algos. * include/std/memory [!_GLIBCXX_HOSTED]: Omit <bits/stl_tempbuf.h> in freestanding * include/bits/algorithmfwd.h [!_GLIBCXX_HOSTED]: Omit leftover random_shuffle and stable_partition definition. * include/bits/stl_algo.h [!_GLIBCXX_HOSTED]: Omit random_shuffle and stable_partition from freestanding. * include/bits/ranges_algo.h [!_GLIBCXX_HOSTED]: Omit stable_partition from freestanding. * include/bits/concept_check.h: Remove needless HOSTED check. * include/std/iterator: Include <bits/ranges_base.h>. * include/std/numeric (__cpp_lib_parallel_algorithms): Do not define for freestanding. * include/std/functional (__cpp_lib_boyer_moore_searcher): Likewise. * testsuite/lib/prune.exp: Match error for hosted-only libstdc++ tests.