aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
AgeCommit message (Collapse)AuthorFilesLines
2024-12-03libstdc++: Stop using _Self typedefs in std::list iteratorsJonathan Wakely1-19/+21
We can just use the injected-class-name instead of defining a new name. That seems simpler. libstdc++-v3/ChangeLog: * include/bits/stl_list.h (_List_iterator): Remove _Self typedef and just use injected-class-name instead. (_List_const_iterator): Likewise.
2024-12-03libstdc++: Refactor std::list::size() for cxx11 ABIJonathan Wakely1-82/+97
Remove some preprocessor conditionals by moving the _M_size member for the cxx11 ABI into a new base class, which is empty for the gcc4-compat ABI. Move some unused members that are only retained for ABI compatibility to the end of _List_base and add an explanatory comment. Stop using list::_M_node_count and list::_D_distance and then move them to the end of std::list with a comment too. libstdc++-v3/ChangeLog: * include/bits/stl_list.h (_List_size): New struct. (_List_node_header): Replace _M_size member with _List_size base class. (_List_node_header(_List_node_header&&)): Replace explicit uses of _M_size with initializing the base. (_List_node_header::_M_init): Likewise. (_List_base::_S_distance, _List_base::_M_distance) (_List_base::_M_node_count): Move to end of class body and add comment. (list::_S_distance, list::_M_node_count): Likewise. (list::size): Inline _M_node_count effects to here. (list::splice(iterator, list&, iterator, iterator)): Use #if and call std::distance instead of _S_distance.
2024-12-03libstdc++: Make std::vector<bool> constructor noexcept (LWG 3778)Jonathan Wakely2-1/+88
LWG 3778 was approved in November 2022. We already implement all the changes except for one, which this commit does. The new test verifies all the changes from LWG 3778, not just the one implemented here. libstdc++-v3/ChangeLog: * include/bits/stl_bvector.h (vector(const allocator_type&)): Add noexcept, as per LWG 3778. * testsuite/23_containers/vector/bool/cons/lwg3778.cc: New test.
2024-12-03libstdc++: Fix constraints on std::optional converting constructors [PR117889]Jonathan Wakely3-19/+25
The converting constructors had the same bug as the converting assignments, so need the same fix as r15-5833-gc2c7d71eeeab7c. libstdc++-v3/ChangeLog: PR libstdc++/117889 PR libstdc++/117858 * include/std/optional (optional(const optional<U>&)): Fix copy and paste error in constraints. (optional(optional<U>&&)): Likewise. * testsuite/20_util/optional/assignment/117858.cc: Move to ... * testsuite/20_util/optional/cons/117858.cc: New test.
2024-12-03Daily bump.GCC Administrator1-0/+13
2024-12-02libstdc++: Simplify std::_Destroy using 'if constexpr'Jonathan Wakely1-6/+27
This is another place where we can use 'if constexpr' to replace dispatching to a specialized class template, improving compile times and avoiding a function call. libstdc++-v3/ChangeLog: * include/bits/stl_construct.h (_Destroy(FwdIter, FwdIter)): Use 'if constexpr' instead of dispatching to a member function of a class template. (_Destroy_n(FwdIter, Size)): Likewise. (_Destroy_aux, _Destroy_n_aux): Only define for C++98. Reviewed-by: Patrick Palka <ppalka@redhat.com>
2024-12-02libstdc++: Disable deprecated warnings for std::rel_ops in std.ccJonathan Wakely1-0/+3
This avoids some warnings when building the std module. libstdc++-v3/ChangeLog: * src/c++23/std.cc.in: Disable deprecated warnings when exporting std::rel_ops members.
2024-12-01Daily bump.GCC Administrator1-0/+38
2024-11-30libstdc++: Improve new testcase for std::optional assignment [PR117858]Jonathan Wakely1-0/+1
The copy & paste bug affected two assignment operators, so ensure the new test covers both. libstdc++-v3/ChangeLog: PR libstdc++/117858 * testsuite/20_util/optional/assignment/117858.cc: Also test assignment from rvalue optional.
2024-11-30libstdc++: Fix constraints on std::optional converting assignments [PR117858]Jonathan Wakely2-2/+18
It looks like I copied these constraints from operator=(U&&) and didn't correct them to account for the parameter being optional<U> not U. libstdc++-v3/ChangeLog: PR libstdc++/117858 * include/std/optional (operator=(const optional<U>&)): Fix copy and paste error in constraints. (operator=(optional<U>&&)): Likewise. * testsuite/20_util/optional/assignment/117858.cc: New test.
2024-11-30libstdc++: Move std::monostate to <utility> for C++26 (P0472R2)Jonathan Wakely7-30/+128
Another C++26 paper just approved in Wrocław. The std::monostate class is defined in <variant> since C++17, but for C++26 it should also be available in <utility>. libstdc++-v3/ChangeLog: * include/Makefile.am: Add bits/monostate.h. * include/Makefile.in: Regenerate. * include/std/utility: Include <bits/monostate.h>. * include/std/variant (monostate, hash<monostate>): Move definitions to ... * include/bits/monostate.h: New file. * testsuite/20_util/headers/utility/synopsis.cc: Add monostate and hash<monostate> declarations. * testsuite/20_util/monostate/requirements.cc: New test.
2024-11-30libstdc++: Improve test for <utility> synopsisJonathan Wakely1-6/+102
libstdc++-v3/ChangeLog: * testsuite/20_util/headers/utility/synopsis.cc: Add declarations from C++11 and later.
2024-11-30c++: Implement C++26 P3176R1 - The Oxford variadic commaJakub Jelinek3-9/+9
While we are already in stage3, I wonder if implementing this small paper wouldn't be useful even for GCC 15, so that we have in the GCC world one extra year of deprecation of variadic ellipsis without preceding comma. The paper just deprecates something, I'd hope most of the C++ code in the wild when it uses variadic functions at all uses the comma before the ellipsis. 2024-11-30 Jakub Jelinek <jakub@redhat.com> gcc/c-family/ * c.opt (Wdeprecated-variadic-comma-omission): New option. * c.opt.urls: Regenerate. * c-opts.cc (c_common_post_options): Default to -Wdeprecated-variadic-comma-omission for C++26 or -Wpedantic. gcc/cp/ * parser.cc: Implement C++26 P3176R1 - The Oxford variadic comma. (cp_parser_parameter_declaration_clause): Emit -Wdeprecated-variadic-comma-omission warnings. gcc/ * doc/invoke.texi (-Wdeprecated-variadic-comma-omission): Document. gcc/testsuite/ * g++.dg/cpp26/variadic-comma1.C: New test. * g++.dg/cpp26/variadic-comma2.C: New test. * g++.dg/cpp26/variadic-comma3.C: New test. * g++.dg/cpp26/variadic-comma4.C: New test. * g++.dg/cpp26/variadic-comma5.C: New test. * g++.dg/cpp1z/fold10.C: Expect a warning for C++26. * g++.dg/ext/attrib33.C: Likewise. * g++.dg/cpp1y/lambda-generic-variadic19.C: Likewise. * g++.dg/cpp2a/lambda-generic10.C: Likewise. * g++.dg/cpp0x/lambda/lambda-const3.C: Likewise. * g++.dg/cpp0x/variadic164.C: Likewise. * g++.dg/cpp0x/variadic17.C: Likewise. * g++.dg/cpp0x/udlit-args-neg.C: Likewise. * g++.dg/cpp0x/variadic28.C: Likewise. * g++.dg/cpp0x/gen-attrs-33.C: Likewise. * g++.dg/cpp23/explicit-obj-diagnostics3.C: Likewise. * g++.old-deja/g++.law/operators15.C: Likewise. * g++.old-deja/g++.mike/p811.C: Likewise. * g++.old-deja/g++.mike/p12306.C (printf): Add , before ... . * g++.dg/analyzer/fd-bind-pr107783.C (bind): Likewise. * g++.dg/cpp0x/vt-65790.C (printf): Likewise. libstdc++-v3/ * include/std/functional (_Bind_check_arity): Add , before ... . * include/bits/refwrap.h (_Mem_fn_traits, _Weak_result_type_impl): Likewise. * include/tr1/type_traits (is_function): Likewise.
2024-11-29Daily bump.GCC Administrator1-0/+43
2024-11-28libstdc++: Use std::_Destroy in std::stacktraceJonathan Wakely1-2/+1
This benefits from the optimizations in std::_Destroy which avoid doing any work when using std::allocator. libstdc++-v3/ChangeLog: * include/std/stacktrace (basic_stacktrace::_M_impl::_M_resize): Use std::_Destroy to destroy removed elements.
2024-11-28libstdc++: Reorder printer registrations in printers.pyJonathan Wakely1-4/+5
Register StdIntegralConstantPrinter with the other C++11 printers, and register StdTextEncodingPrinter after C++20 printers. libstdc++-v3/ChangeLog: * python/libstdcxx/v6/printers.py: Reorder registrations.
2024-11-28libstdc++: Fix allocator-extended move ctor for std::basic_stacktrace [PR117822]Jonathan Wakely2-5/+204
libstdc++-v3/ChangeLog: PR libstdc++/117822 * include/std/stacktrace (stacktrace(stacktrace&&, const A&)): Fix typo in qualified-id for is_always_equal trait. * testsuite/19_diagnostics/stacktrace/stacktrace.cc: Test allocator-extended constructors and allocator propagation.
2024-11-28libstdc++: Deprecate std::rel_ops namespace for C++20Jonathan Wakely4-3/+12
This is deprecated in the C++20 standard and will be removed at some point. libstdc++-v3/ChangeLog: * include/bits/stl_relops.h (rel_ops): Add deprecated attribute. * testsuite/20_util/headers/utility/using_namespace_std_rel_ops.cc: Add dg-warning for -Wdeprecated warnings. * testsuite/20_util/rel_ops.cc: Likewise. * testsuite/util/testsuite_containers.h: Disable -Wdeprecated warnings when using rel_ops.
2024-11-28libstdc++: Reduce duplication in Doxygen comments for std::listJonathan Wakely1-107/+35
We have a number of comments which are duplicated for C++98 and C++11 overloads, where the signatures are slightly different. Instead of duplicating the comments that are 90% identical, just use a single comment that can apply to both. In some cases this means saying "an iterator" instead of "A const iterator" but that's fine, a std::list::const_iterator is still an iterator (and a non-const iterator is a valid argument to those functions because they'll implicitly convert to const_iterator). In two cases the @return description just needs to say that it returns void for C++98 and an iterator otherwise. libstdc++-v3/ChangeLog: * include/bits/stl_list.h: Reduce duplication in doxygen comments.
2024-11-28c++: Implement P2662R3, Pack Indexing [PR113798]Marek Polacek1-1/+1
This patch implements C++26 Pack Indexing, as described in <https://wg21.link/P2662R3>. The issue discussing how to mangle pack indexes has not been resolved yet <https://github.com/itanium-cxx-abi/cxx-abi/issues/175> and I've made no attempt to address it so far. Unlike v1, which used augmented TYPE/EXPR_PACK_EXPANSION codes, this version introduces two new codes: PACK_INDEX_EXPR and PACK_INDEX_TYPE. Both carry two operands: the pack expansion and the index. They are handled in tsubst_pack_index: substitute the index and the pack and then extract the element from the vector (if possible). To handle pack indexing in a decltype or with decltype(auto), there is also the new PACK_INDEX_PARENTHESIZED_P flag. With this feature, it's valid to write something like using U = tmpl<Ts...[Is]...>; where we first expand the template argument into Ts...[Is#0], Ts...[Is#1], ... and then substitute each individual pack index. PR c++/113798 gcc/cp/ChangeLog: * constexpr.cc (potential_constant_expression_1) <case PACK_INDEX_EXPR>: New case. * cp-objcp-common.cc (cp_common_init_ts): Mark PACK_INDEX_TYPE and PACK_INDEX_EXPR. * cp-tree.def (PACK_INDEX_TYPE): New. (PACK_INDEX_EXPR): New. * cp-tree.h (WILDCARD_TYPE_P): Also check PACK_INDEX_TYPE. (PACK_INDEX_CHECK): Define. (PACK_INDEX_P): Define. (PACK_INDEX_PACK): Define. (PACK_INDEX_INDEX): Define. (PACK_INDEX_PARENTHESIZED_P): Define. (make_pack_index): Declare. (pack_index_element): Declare. * cxx-pretty-print.cc (cxx_pretty_printer::expression) <case PACK_INDEX_EXPR>: New case. (cxx_pretty_printer::type_id) <case PACK_INDEX_TYPE>: New case. * error.cc (dump_type) <case PACK_INDEX_TYPE>: New case. (dump_type_prefix): Handle PACK_INDEX_TYPE. (dump_type_suffix): Likewise. (dump_expr) <case PACK_INDEX_EXPR>: New case. * mangle.cc (write_type) <case PACK_INDEX_TYPE>: New case. * module.cc (trees_out::type_node) <case PACK_INDEX_TYPE>: New case. (trees_in::tree_node) <case PACK_INDEX_TYPE>: New case. * parser.cc (cp_parser_next_tokens_are_pack_index_p): New. (cp_parser_pack_index): New. (cp_parser_primary_expression): Handle a C++26 pack-index-expression. (cp_parser_unqualified_id): Handle a C++26 pack-index-specifier. (cp_parser_nested_name_specifier_opt): See if a pack-index-specifier follows. (cp_parser_qualifying_entity): Handle a C++26 pack-index-specifier. (cp_parser_decltype_expr): Set id_expression_or_member_access_p for pack indexing. (cp_parser_mem_initializer_id): Handle a C++26 pack-index-specifier. (cp_parser_simple_type_specifier): Likewise. (cp_parser_base_specifier): Likewise. * pt.cc (iterative_hash_template_arg) <case PACK_INDEX_TYPE, PACK_INDEX_EXPR>: New case. (find_parameter_packs_r) <case PACK_INDEX_TYPE, PACK_INDEX_EXPR>: New case. (make_pack_index): New. (tsubst_pack_index): New. (tsubst): Avoid tsubst on PACK_INDEX_TYPE. <case TYPENAME_TYPE>: Add a call to error. <case PACK_INDEX_TYPE>: New case. (tsubst_expr) <case PACK_INDEX_EXPR>: New case. (dependent_type_p_r): Return true for PACK_INDEX_TYPE. (type_dependent_expression_p): Recurse on PACK_INDEX_PACK for PACK_INDEX_EXPR. * ptree.cc (cxx_print_type) <case PACK_INDEX_TYPE>: New case. * semantics.cc (finish_parenthesized_expr): Set PACK_INDEX_PARENTHESIZED_P for PACK_INDEX_EXPR. (finish_type_pack_element): Adjust error messages. (pack_index_element): New. * tree.cc (cp_tree_equal) <case PACK_INDEX_EXPR>: New case. (cp_walk_subtrees) <case PACK_INDEX_TYPE, PACK_INDEX_EXPR>: New case. * typeck.cc (structural_comptypes) <case PACK_INDEX_TYPE>: New case. libstdc++-v3/ChangeLog: * testsuite/20_util/tuple/element_access/get_neg.cc: Adjust dg-prune-output. gcc/testsuite/ChangeLog: * g++.dg/cpp26/pack-indexing1.C: New test. * g++.dg/cpp26/pack-indexing2.C: New test. * g++.dg/cpp26/pack-indexing3.C: New test. * g++.dg/cpp26/pack-indexing4.C: New test. * g++.dg/cpp26/pack-indexing5.C: New test. * g++.dg/cpp26/pack-indexing6.C: New test. * g++.dg/cpp26/pack-indexing7.C: New test. * g++.dg/cpp26/pack-indexing8.C: New test. * g++.dg/cpp26/pack-indexing9.C: New test. * g++.dg/cpp26/pack-indexing10.C: New test. * g++.dg/cpp26/pack-indexing11.C: New test. * g++.dg/modules/pack-index-1_a.C: New test. * g++.dg/modules/pack-index-1_b.C: New test.
2024-11-28libstdc++: Include <sys/cdefs.h> in os_defines.h for FreeBSD [PR117210]Jonathan Wakely2-0/+4
This is needed so that __LONG_LONG_SUPPORTED is defined before we depend on it. libstdc++-v3/ChangeLog: PR libstdc++/117210 * config/os/bsd/dragonfly/os_defines.h: Include <sys/cdefs.h>. * config/os/bsd/freebsd/os_defines.h: Likewise.
2024-11-28Daily bump.GCC Administrator1-0/+68
2024-11-27optimize basic_stringJan Hubicka1-6/+19
Add __builtin_unreachable conditionls to declare value ranges of basic_string::length(). FIx max_size() to return actual max size using logic similar to std::vector. Aviod use of size() in empty() to save some compile time overhead. As disucced, max_size() change is technically ABI breaking, but hopefully this does not really matter in practice. Change of length() breaks empty-loop testcase where we now optimize the loop only after inlining, so template is updated to check cddce3 instead of cddce2. This is PR117764. With these chages we now optimize out unused strings as tested in string-1.C libstdc++-v3/ChangeLog: * include/bits/basic_string.h (basic_string::size(), basic_string::length(), basic_string::capacity()): Add __builtin_unreachable to declare value ranges. (basic_string::empty()): Implement directly (basic_string::max_size()): Account correctly the terminating 0 and limits implied by ptrdiff_t. gcc/testsuite/ChangeLog: * g++.dg/tree-ssa/empty-loop.C: xfail optimization at cddce2 and check it happens at cddce3. * g++.dg/tree-ssa/string-1.C: New test.
2024-11-27libstdc++: Remove __builtin_expect from consteval assertionJonathan Wakely1-6/+9
libstdc++-v3/ChangeLog: * include/bits/c++config (__glibcxx_assert): Remove useless __builtin_expect from constexpr-only assertion. Improve comments.
2024-11-27libstdc++: Add cold attribute to assertion failure functions [PR117650]Jonathan Wakely2-2/+2
This helps the compiler to split the cold path into a separate clone, so that the hot path is a smaller function that uses less icache, and the cold path is only fetched into the icache if actually executed. libstdc++-v3/ChangeLog: PR libstdc++/117650 * include/bits/c++config (__glibcxx_assert_fail): Add cold attribute. * include/debug/formatter.h (_Error_formatter::_M_error): Likewise.
2024-11-27libstdc++/ranges: make _RangeAdaptorClosure befriend operator|Patrick Palka2-8/+21
This declares the range adaptor pipe operators a friend of the _RangeAdaptorClosure base class so that the std module doesn't need to export them for ADL to find them. Note that we deliberately don't define these pipe operators as hidden friends, see r14-3293-g4a6f3676e7dd9e. libstdc++-v3/ChangeLog: * include/std/ranges (views::__adaptor::_RangeAdaptorClosure): Befriend both operator| overloads. * src/c++23/std.cc.in: Don't export views::__adaptor::operator|. Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2024-11-27libstdc++: module std fixesJason Merrill1-28/+36
Some tests were failing due to the exported using declaration of iter_move conflicting with friend declarations; the exported using needs to be in the inline namespace, like the customization point itself, rather than std::ranges. Also add a few missing exports. Some tests failed to find some operators defined in implementation-detail namespaces; this exports them as well, but as previously discussed it's probably preferable to make those operators friends so ADL can find them that way. libstdc++-v3/ChangeLog: * src/c++23/std.cc.in: Fix iter_move/swap. Add fold_left_first, to, concat, and some operators.
2024-11-27libstdc++: Add debug assertions to std::list and std::forward_listJonathan Wakely2-2/+14
While working on fancy pointer support for the linked lists I noticed they didn't have any debug assertions. This adds the obvious non-empty assertions to front() and back(). libstdc++-v3/ChangeLog: * include/bits/forward_list.h (forward_list::front): Add non-empty assertions. * include/bits/stl_list.h (list::front, list::back): Add non-empty assertions.
2024-11-27libstdc++: Simplify std::forward_list assignment using 'if constexpr'Jonathan Wakely1-40/+79
Use diagnostic pragmas to allow using `if constexpr` in C++11 mode, so that we don't need to use tag dispatching. The unused member functions are preserved for the purposes of explicit instantiations. The _M_assign function template can be removed, because member function templates aren't instantiated by explicit instantiations anyway. libstdc++-v3/ChangeLog: * include/bits/forward_list.h (operator=(forward_list&&)): Use if constexpr instead of dispatching to _M_move_assign. (assign(InputIterator, InputIterator)): Use if constexpr instead of dispatching to _M_assign. (assign(size_type, const T&)): Use if constexpr instead of dispatching to _M_assign_n. (_M_move_assign, _M_assign_n): Do not define for versioned namespace. (_M_assign): Remove.
2024-11-27libstdc++: Simplify std::list assignment using 'if constexpr'Jonathan Wakely1-2/+27
Use diagnostic pragmas to allow using `if constexpr` in C++11 mode, so that we don't need to use tag dispatching. The _M_move_assign overloads that were previously used for tag dispatching are no longer used, but are retained here (at least for the default config) so that an explicit instantiation will still define those members. This ensures that old code which expects an explicit instantiation in some other translation unit will still link. I'm not sure if that's really needed, we should probably have a policy about whether we support explicit instantiations where the declaration and definition use different versions of the headers. libstdc++-v3/ChangeLog: * include/bits/stl_list.h (operator=(list&&)): Use if constexpr instead of dispatching to _M_move_assign. (_M_move_assign): Do not define for versioned namespace.
2024-11-27libstdc++: Fix unsigned wraparound in codecvt::do_length [PR105857]Jonathan Wakely3-6/+33
When the max argument to std::codecvt<wchar_t, char, mbstate_t>::length is SIZE_MAX/4+1 or greater the multiplication with sizeof(wchar_t) will wrap to a small value, and the alloca call will have a buffer that's smaller than requested. The call to mbsnrtowcs then has a buffer that is smaller than the value passed as the buffer length. When libstdc++.so is built with -D_FORTIFY_SOURCE=3 the mismatched buffer and length will get detected and will abort inside Glibc. When it doesn't abort, there's no buffer overflow because Glibc's mbsnrtowcs has the same len * sizeof(wchar_t) calculation to determine the size of the buffer in bytes, and that will wrap to the same small number as the alloca argument. So luckily Glibc agrees with the caller about the real size of the buffer, and won't overflow it. Even when the max argument isn't large enough to wrap, it can still be much too large to safely pass to alloca, so we should limit that. We already have a loop that processes chunks so that we can handle null characters in the middle of the input. If we limit the alloca buffer to 4kB then we'll just loop each time that buffer is filled. libstdc++-v3/ChangeLog: PR libstdc++/105857 * config/locale/dragonfly/codecvt_members.cc (do_length): Limit size of alloca buffer to 4k. * config/locale/gnu/codecvt_members.cc (do_length): Likewise. * testsuite/22_locale/codecvt/length/wchar_t/105857.cc: New test.
2024-11-27Daily bump.GCC Administrator1-0/+45
2024-11-26libstdc++: Add -fno-assume-sane-operators-new-delete to test [PR117751]Jonathan Wakely1-1/+1
libstdc++-v3/ChangeLog: PR libstdc++/117751 * testsuite/18_support/50594.cc: Edit dg-options to include the -fno-assume-sane-operators-new-delete option.
2024-11-26improve std::deque::_M_reallocate_mapJan Hubicka2-1/+10
Looking into reason why we still do throw_bad_alloc in clang binary I noticed that quite few calls come from deque::_M_reallocate_map. This patch adds unreachable to limit the size of realloc_map. _M_reallocate_map is called only if new size is smaller then max_size. map is an array holding pointers to entries of fixed size. Since rellocation is done by doubling the map size, I think the maximal size of map allocated is max_size / deque_buf_size rounded up times two. This should be also safe for overflows since we have extra bit. map size is always at least 8. Theoretically this computation may be wrong for very large T, but in that case callers should never reallocate. On the testcase I get: jh@shroud:~> ~/trunk-install-new4/bin/g++ -O2 dq.C -c ; size -A dq.o | grep text .text 284 0 .text._ZNSt5dequeIiSaIiEE17_M_reallocate_mapEmb 485 0 .text.unlikely 10 0 jh@shroud:~> ~/trunk-install-new5/bin/g++ -O2 dq.C -c ; size -A dq.o | grep text .text 284 0 .text._ZNSt5dequeIiSaIiEE17_M_reallocate_mapEmb 465 0 .text.unlikely 10 0 so this saves about 20 bytes of rellocate_map, which I think is worthwhile. Curiously enough gcc14 does: jh@shroud:~> g++ -O2 dq.C -c ; size -A dq.o | grep text .text 604 0 .text.unlikely 10 0 which is 145 bytes smaller. Obvoius difference is that _M_reallocate_map gets inlined. Compiling gcc14 preprocessed file with trunk gives: jh@shroud:~> g++ -O2 dq.C -S ; size -A dq.o | grep text .text 762 0 .text.unlikely 10 0 So inlining is due to changes at libstdc++ side, but code size growth is due to something else. For clang this reduced number of thris_bad_new_array_length from 121 to 61. libstdc++-v3/ChangeLog: * include/bits/deque.tcc (std::deque::_M_reallocate_map): Add __builtin_unreachable check to declare that maps are not very large. * include/bits/stl_deque.h (std::deque::size): Add __builtin_unreachable to check for maximal size of map. gcc/testsuite/ChangeLog: * g++.dg/tree-ssa/deque-1.C: New test. * g++.dg/tree-ssa/deque-2.C: New test.
2024-11-26libstdc++: Add conditional noexcept to range access functionsJonathan Wakely8-19/+134
As an extension, this adds conditional noexcept to std::begin, std::end, and std::ssize. libstdc++-v3/ChangeLog: * include/bits/range_access.h (begin, end, ssize): Add conditional noexcept. * testsuite/18_support/initializer_list/range_access.cc: Check results and noexcept-specifier for std::begin and std::end. * testsuite/24_iterators/headers/iterator/range_access_c++11.cc: Check for conditional noexcept on std::begin and std::end. * testsuite/24_iterators/headers/iterator/range_access_c++14.cc: Likewise. * testsuite/24_iterators/headers/iterator/range_access_c++17.cc: Likewise. * testsuite/24_iterators/range_access/range_access.cc: Check conditional noexcept is correct. * testsuite/24_iterators/range_access/range_access_cpp17.cc: Check std::size, std::empty and std::data. * testsuite/24_iterators/range_access/range_access_cpp20.cc: Check conditional noexcept on std::ssize.
2024-11-26libstdc++: Improve Doxygen comments in <forward_list>Jonathan Wakely1-61/+62
Use Markdown backticks to format comments, instead of Doxygen @c and @a commands. libstdc++-v3/ChangeLog: * include/bits/forward_list.h: Use Markdown in Doxygen comments.
2024-11-26libstdc++: Move std::error_category symbol to separate file [PR117630]Jonathan Wakely4-15/+56
As described in PR 117630 the cow-stdexcept.cc file pulls in symbols from system_error.cc, which are not actually needed there. Moving the definition of error_category::_M_message to a separate file should solve it. libstdc++-v3/ChangeLog: PR libstdc++/117630 * src/c++11/Makefile.am: Add new file. * src/c++11/Makefile.in: Regnerate. * src/c++11/cow-stdexcept.cc (error_category::_M_message): Move member function definition to ... * src/c++11/cow-system_error.cc: New file.
2024-11-21Daily bump.GCC Administrator1-0/+13
2024-11-20libstdc++: Use const_iterator in std::set::find<K> return typeJonathan Wakely1-1/+1
François noticed that the "wrong" type is used in the return type for a std::set member function template. The iterator for our std::set is the same type as const_iterator, so this doesn't actually matter. But it's clearer if the return type matches the type used in the function body. libstdc++-v3/ChangeLog: * include/bits/stl_set.h (set::find): Use const_iterator in return type, not iterator.
2024-11-20libstdc++: Fix std::unordered_set::emplace optimization [PR117686]Jonathan Wakely2-2/+18
The __is_key_type specialization that matches a pair<key_type, T> argument is intended for std::unordered_map, not for std::unordered_set<std::pair<K,T>>. This uses a pair<const Args&...> as the template argument for __is_key_type, so that it won't match a set's key_type. libstdc++-v3/ChangeLog: PR libstdc++/117686 * include/bits/hashtable.h (_Hashtable::_M_emplace_uniq): Adjust usage of __is_key_type to avoid false positive. * testsuite/23_containers/unordered_set/insert/117686.cc: New test.
2024-11-20Daily bump.GCC Administrator1-0/+4
2024-11-19libstdc++: remove JSON comment.Jason Merrill1-1/+0
Standard JSON doesn't have comments, and it seems this file needs to be conforming, not the common JSON-with-comments dialect. libstdc++-v3/ChangeLog: * src/c++23/libstdc++.modules.json.in: Remove C++ comment.
2024-11-19Daily bump.GCC Administrator1-0/+21
2024-11-18testsuite: move dg-test cleanup code from gcc-dg.exp to its own fileDavid Malcolm1-0/+1
I need to use this cleanup logic for the testsuite for libdiagnostics where it's too awkward to directly use gcc-dg.exp itself. No functional change intended. gcc/testsuite/ChangeLog: * lib/dg-test-cleanup.exp: New file, from material moved from lib/gcc-dg.exp. * lib/gcc-dg.exp: Add load_lib of dg-test-cleanup.exp. (cleanup-after-saved-dg-test): Move to lib/dg-test-cleanup.exp. (dg-test): Likewise for override. (initialize_prune_notes): Likewise. libatomic/ChangeLog: * testsuite/lib/libatomic.exp: Add "load_gcc_lib dg-test-cleanup.exp". libgomp/ChangeLog: * testsuite/lib/libgomp.exp: Add "load_gcc_lib dg-test-cleanup.exp". libitm/ChangeLog: * testsuite/lib/libitm.exp: Add "load_gcc_lib dg-test-cleanup.exp". libphobos/ChangeLog: * testsuite/lib/libphobos-dg.exp: Add "load_gcc_lib dg-test-cleanup.exp". libstdc++-v3/ChangeLog: * testsuite/lib/libstdc++.exp: Add "load_gcc_lib dg-test-cleanup.exp". libvtv/ChangeLog: * testsuite/lib/libvtv.exp: Add "load_gcc_lib dg-test-cleanup.exp". Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-11-18libstdc++: Fix invalid casts in unordered container merge functionsJonathan Wakely1-16/+27
François pointed out that static_cast<__node_ptr>(&_M_before_begin) is invalid, because _M_before_begin is only a node-base not a node. Refactor the new merge overloads to only cast when we know we have a valid node. He also pointed out some optimizations to allow reusing hash codes that might be cached in the node. The _M_src_hash_code function already has the right logic to decide when a cached hash code can be reused by a different _Hashtable object. libstdc++-v3/ChangeLog: * include/bits/hashtable.h (_Hashtable::_M_src_hash_code): Improve comments. (_Hashtable::_M_merge_unique(_Hashtable&)): Use pointer_traits to get before-begin pointer. Only use static_cast on valid nodes, not the before-begin pointer. Reuse a hash code cached in the node when possible. (_Hashtable::_M_merge_multi(_Hashtable&)): Likewise. Reviewed-by: François Dumont <fdumont@gcc.gnu.org>
2024-11-18libstdc++: Update reference to Angelika Langer's articleGerald Pfeifer2-2/+2
libstdc++-v3: * doc/xml/manual/allocator.xml: Update reference to Angelika Langer's article. * doc/html/manual/memory.html: Regenerate.
2024-11-18Daily bump.GCC Administrator1-0/+29
2024-11-17libstdc++: add module std [PR106852]Jason Merrill8-16/+4156
This patch introduces an installed source form of module std and std.compat. To help a build system find them, we install a libstdc++.modules.json file alongside libstdc++.so, which tells the build system where the files are and any special flags it should use when compiling them (none, in this case). The format is from a proposal in SG15. The build system can find this file with 'gcc -print-file-name=libstdc++.modules.json'. It seems preferable to use a relative path from this file to the sources so that moving the installation doesn't break the reference, but I didn't see any obvious way to compute that without relying on coreutils, perl, or python, so I wrote a POSIX shell script for it. The .. canonicalization bits aren't necessary since I discovered $(abspath), but I guess I might as well leave them in. Currently this installs the sources under $(gxx_include_dir)/bits/, i.e. /usr/include/c++/15/bits. So with my -fsearch-include-path change, std.cc can be compiled with g++ -fsearch-include-path bits/std.cc. Note that if someone actually tries to #include <bits/std.cc> it will fail with "error: module control-line cannot be in included file". Any ideas about a more user-friendly way to express "compile module std" are welcome. The sources currently have the extension .cc, like other source files. std.cc started with m.cencora's implementation in PR114600. I've made some adjustments, but more is probably desirable, e.g. of the <algorithm> handling of namespace ranges, and to remove exports of templates that are only specialized in a particular header. I've filled in a bunch of missing exports, and added some FIXMEs where I noticed bits that are not implemented yet. Since bits/stdc++.h also intends to include the whole standard library, I include it rather than duplicate it. But stdc++.h comments out <execution>, due to TBB issues; I include it separately and suppress TBB usage, so module std won't currently provide parallel execution. It seemed most convenient for the two files to be monolithic so we don't need to worry about include paths. So the C library names that module std.compat exports in both namespace std and :: are a block of code that is appended to both files, adjusted based on whether the macro STD_COMPAT is defined before the block. In this implementation std.compat imports std; it would also be valid for it to duplicate everything in std. I see the libc++ std.compat also imports std. As discussed in the PR, module std is supported in C++20 mode even though it was added in C++23. Changes to test module std will follow in a separate patch. In my testing I've noticed a few compiler bugs that break various testcases, so I don't expect to enable module std testing by default at first. PR libstdc++/106852 libstdc++-v3/ChangeLog: * include/bits/version.def: Add __cpp_lib_modules. * include/bits/version.h: Regenerate. * src/c++23/Makefile.am: Add modules std and std.compat. * src/c++23/Makefile.in: Regenerate. * src/c++23/std-clib.cc.in: New file. * src/c++23/std.cc.in: New file. * src/c++23/std.compat.cc.in: New file. * src/c++23/libstdc++.modules.json.in: New file. contrib/ChangeLog: * relpath.sh: New file.
2024-11-17libstdc++: Move a gcc.gnu.org link to httpsGerald Pfeifer2-2/+2
libstdc++-v3: * doc/xml/manual/intro.xml: Move a gcc.gnu.org link to https. * doc/html/manual/license.html: Regenerate.
2024-11-17libstdc++: Update link to Angelika Langer's bookGerald Pfeifer2-2/+2
libstdc++-v3: * doc/xml/manual/io.xml: Update link to Angelika Langer's book. * doc/html/manual/streambufs.html: Regenerate.