This improves the code generation slightly for std::string because of
aliasing. In many cases the length will be read again and the store of
the null character will cause the length to be re-read due to aliasing
requirements of the char type. So swapping around the stores will allow
the length not to have to be reloaded from memory and will allow
for more optimizations.
Bootstrapped and tested on x86_64-linux-gnu.
libstdc++-v3/ChangeLog:
* include/bits/basic_string.h (basic_string::M_set_length): Swap
around the order of traits_type::assign and _M_length so that
_M_length is at the end.
Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
These three changes are needed to make <mdspan> compatible with Clang:
- the type alias _Storage must occur before its first use.
- the friend declarations of function must match exactly, including
noexcept and constexpr.
- the 'template' in typename T::template type<double>.
libstdc++-v3/ChangeLog:
* include/std/mdspan (extents::_Storage): Move type alias before
its first use.
(__mdspan::__static_extents): Add missing noexcept and constexpr
to friend declaration in extents.
(__mdspan::__dynamic_extents): Ditto.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
The following patch attempts to implement CWG1670 and related LWG4468.
2025-11-19 Jakub Jelinek <jakub@redhat.com>
gcc/cp/
* parser.cc (cp_parser_conversion_type_id): Implement C++ DR1670
- auto as conversion-type-id. Pedwarn on conversion operators
with placeholder return type.
gcc/testsuite/
* g++.dg/DRs/dr1670-1.C: New test.
* g++.dg/DRs/dr1670-2.C: New test.
* g++.dg/DRs/dr1670-3.C: New test.
* g++.dg/modules/auto-1_a.H: Use dg-options instead of
dg-additional-options.
* g++.dg/modules/auto-1_b.C: Likewise.
* g++.dg/cpp1y/auto-fn12.C: Likewise.
* g++.dg/cpp1y/auto-fn13.C: Add empty dg-options.
* g++.dg/cpp1y/auto-fn22.C: Likewise.
* g++.dg/cpp1y/constexpr-assert2.C: Likewise.
* g++.dg/cpp1y/auto-fn44.C: Add dg-options -Wpedantic and expect
further warnings.
* g++.dg/cpp1y/auto-fn50.C: Likewise.
* g++.dg/cpp0x/auto9.C: Expect two errors always rather than just
for C++11.
libstdc++-v3/
* include/std/type_traits (constant_wrapper conversion operator):
Use decltype(value) instead of decltype(auto). Resolves LWG4468.
This patch implements the proposed resolution of
https://cplusplus.github.io/LWG/issue4477
The PR complains that one can't successfully throw from constructor
in placement new in a constant expression and catch that exception
later on. The problem is while P2747R2 made placement ::operator new
and ::operator new[] constexpr, when the ctor throws it invokes also
these weird placement ::operator delete and ::operator delete[]
which intentionally perform no action, and those weren't constexpr,
so constant expression evaluation failed.
2025-11-19 Jakub Jelinek <jakub@redhat.com>
PR libstdc++/122671
* libsupc++/new (::operator delete, ::operator delete[]): Implement
proposed LWG4477 resolution. Use _GLIBCXX_PLACEMENT_CONSTEXPR for
placement operator deletes.
* g++.dg/cpp26/constexpr-eh17.C: New test.
Make the shared_mutex::try_lock(), shared_timed_mutex::try_lock_until()
and shared_timed_mutex::try_lock_shared_until() all handle errors from
pthread functions consistently by returning false to indicate that the
lock could not be taken. If _GLIBCXX_ASSERTIONS is defined then
unexpected errors, such as EDEADLK and EINVAL will cause an assertion
failure. If _GLIBCXX_ASSERTIONS is not defined then these functions no
longer ever return true incorrectly indicating that they have taken the
lock.
This removes the previous behaviour of looping on EDEADLK in
try_lock_shared_until() and no longer returns true on EINVAL in all of
these functions. (In theory at least it should not be possible to
trigger EINVAL since 5dba17a3e709859968f939354e6e5e8d796012d3.)
Unfortunately my reading of POSIX is that pthread_rwlock_clockrdlock[1],
pthread_rwlock_timedrdlock pthread_rwlock_clockwrlock[2] and
pthread_rwlock_timedwrlock are allowed to deadlock rather than return
EDEADLK when trying to take a lock a second time from the same
thread. This means that the deadlock tests cannot be enabled by
default. I believe that the tests do work with glibc (2.31 & 2.36) and
with the __shared_mutex_cv implementation though.
[1] https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_rwlock_clockrdlock.html
[2] https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_rwlock_clockwrlock.html
libstdc++-v3/ChangeLog:
* include/std/shared_mutex (try_lock, try_lock_until)
(try_lock_shared_until): Respond consistently to errors and
deadlocks.
* testsuite/30_threads/shared_timed_mutex/try_lock_until/116586.cc:
Test deadlock behaviour if possible.
Signed-off-by: Mike Crowe <mac@mcrowe.com>
To reduce instantiation count, function_ref(nontype<&S::x>, r) previously
reused the invoker from function_ref(nontype<&S::x>, &r). This assumed r was
always a reference to S or a derived class. However, this constructor is also
valid for lvalues (but not rvalues) of reference_wrapper specializations.
This patch fixes this by limiting above optimization only to situations,
when argument is not specialization of reference_wrapper. This is achieved
bu comparing __inv_unwrap<_Td>::type with _Td. We use __inv_unwrap because
unwrap_reference_t does not handle cv-qualified types.
PR libstdc++/121858
libstdc++-v3/ChangeLog:
* include/bits/funcref_impl.h
(function_ref::function_ref(nontype<__fn>, _Up&&)): Handle.
reference_wrapper.
* testsuite/20_util/function_ref/call.cc: Call and update
test05(). Add new test06() for reference_wrapper.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
Use the __last_system_error() function and the system_category to
convert the Windows error to a generic one.
libstdc++-v3/ChangeLog:
PR libstdc++/122726
* src/filesystem/ops-common.h [_GLIBCXX_FILESYSTEM_IS_WINDOWS]
(rename): Use __last_system_error to set errno accurately.
* testsuite/27_io/filesystem/operations/rename.cc: Test
error_code matches errc::no_such_file_or_directory.
Add preprocessor checks to std.cc.in for features which are not
supported with the old string ABI.
The COW std::string doesn't properly support C++11 allocators, so the
aliases such as std::pmr::string, std::pmr::u8string etc. are not
defined for the old string ABI.
The std::syncbuf type uses std::string and is not defined for the old
string ABI.
libstdc++-v3/ChangeLog:
* src/c++23/std.cc.in [!__cpp_lib_syncbuf]: Disable exports for
<syncstream> contents when not defined.
[!_GLIBCXX_USE_CXX11_ABI]: Disable exports for pmr aliases in
<string> when not defined.
In my import std testing patch, to work around c++/99000 (include after
import) I move #includes of the util/ headers above the import. And so I
made some adjustments to those headers to support this: adding some missing
dependencies, making sure that in headers that include both importable and
non-importable headers, at least one importable header comes first to work
with my patch to translate e.g. #include <vector> to import <bits/stdc++.h>.
The testsuite_iterators.h avoids a failure in
20_util/specialized_algorithms/uninitialized_copy/constrained.cc from
including <memory> after this header, with a mysterious "no match for
operator<" between long and difference_type.
libstdc++-v3/ChangeLog:
* testsuite/util/testsuite_allocator.h: Move importable headers up.
* testsuite/util/testsuite_common_types.h: Likewise.
* testsuite/util/testsuite_containers.h: Likewise.
* testsuite/util/testsuite_error.h: Move includes inside
include guard.
* testsuite/util/testsuite_greedy_ops.h: #include <cstddef>.
* testsuite/util/testsuite_iterators.h: #include <utility>.
* testsuite/util/testsuite_new_operators.h: #include <cstdlib>.
* testsuite/util/testsuite_random.h: #include <random>.
For most configurations bits/std_mutex.h would already be included by
<syncstream>, but not if configured with _GLIBCXX_USE_CXX11_ABI=0 as the
default, because syncbuf is disabled in that case.
libstdc++-v3/ChangeLog:
PR libstdc++/122698
* src/c++20/syncbuf.cc (__syncbuf_get_mutex): Include <mutex>.
Fix indentation of function body.
/usr/ccs/bin has been replaced by a symlink to /usr/bin since at least
Solaris 11.3, so there's no reason to use that path any longer.
This patch removes all references to it.
Tested on i386-pc-solaris2.11.
2025-11-14 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
* configure.ac (md_exec_prefix): Don't set on Solaris.
* configure: Regenerate.
contrib:
* make_sunver.pl ($elfdump): Remove ccs from path.
gcc:
* config/sol2.h (MD_EXEC_PREFIX): Remove.
libstdc++-v3:
* scripts/extract_symvers.pl: Remove ccs from elfdump path.
A user pointed out that, in DAP mode, gdb would hang while trying to
display a certain vector. See
https://sourceware.org/bugzilla/show_bug.cgi?id=33594
This is caused by a combination of things: the vector is
uninitialized, DAP requires a count of the number of children of a
variable, and libstdc++ printers don't implement the 'num_children'
method, so gdb tries to count children by iterating.
In this case, the vector has a nonsensical size:
(gdb) p myVector
$1 = std::vector of length -34979931, capacity -33992726
This patch adds a 'num_children' method to a subset of the
pretty-printers, in particular ones where I thought the length might
be arbitrarily large and susceptible to being garbage when the object
isn't initialized.
I've also specifically added a check to the vector printer for the
case where the length is negative.
These container printers could be further improved by adding the
'child' method, allowing random access to child objects. However I
haven't done that here.
libstdc++-v3/ChangeLog
* python/libstdcxx/v6/printers.py (StdVectorPrinter._bounds):
New method.
(StdVectorPrinter.to_string): Use it.
(StdVectorPrinter.num_children): New method.
(StdStackOrQueuePrinter.num_children): New method.
(StdMapPrinter.num_children): New method.
(StdSetPrinter.num_children): New method.
(StdDequePrinter._size): New method.
(StdDequePrinter.to_string): Use it.
(StdDequePrinter.num_children): New method.
(Tr1UnorderedSetPrinter.num_children): New method.
(Tr1UnorderedMapPrinter.num_children): New method.
(StdSpanPrinter.num_children): New method.
Previously, _Utf_view accepted any input_range, including reference-to-array
types like char(&)[2], and stored it as the _M_base member. In such cases,
_Utf_view was not assignable, failing the requirements of view concept.
This patch addresses the issue by adding the ranges::view constraint to the
second template parameter of _Utf_view, and for clarity renaming it from
_Range to _View. The constructor is also adjusted to accept its argument
by value (views must be O(1) move-constructible). This prevents implicitly
generated CTAD from deducing a reference type.
This makes _Utf_view consistent with both other standard views and the
wording from P2728R8: Unicode in the Library, Part 1: UTF Transcoding [1].
The explicit CTAD from viewable_range is not defined for _Utf_view because
it depends on views::all_t, views::ref_view, and views::owning_view,
which are declared in <ranges>. Consequently, users must explicitly cast
the argument to a view or specify it as a template parameter.
[1] https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p2728r8.html
libstdc++-v3/ChangeLog:
* include/bits/unicode.h (_Utf_view): Rename the template parameter
from _Range to _View and constrain it with ranges::view.
(_Utf_view::_Utf_view): Accept by value instead of rvalue reference.
* include/std/format (__format::__write_padded): Replace _Utf_view
over const char32_t(&)[1] with span<const char32_t, 1>.
* testsuite/ext/unicode/view.cc: Add checks if specialization
of _Utf_view satisfy view. Wrap arrays into std::span before
constructing _Utf_view.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
According to the standard the first n characters of a bitset constructor
string need to be checked instead of only N.
libstdc++-v3/ChangeLog:
PR libstdc++/121054
* include/std/bitset: Add string check to constructor.
* testsuite/20_util/bitset/121054.cc: New test.
* testsuite/20_util/bitset/cons/constexpr_c++23.cc: Fix.
Co-authored-by: Jonathan Wakely <jwakely@redhat.com>
This patch changes the implementation of bind_front<f> and bind_back<f> to
return a _Bind_front_t<_Bind_fn_t<f>, ...> and _Bind_back_t<_Bind_fn_t<f>, ...>
respectively, replacing the previous lambda-based implementation. The prior use
of a lambda caused non-conforming behavior with respect to C++23 [func.require]
p8, which requires that bind_front<f>(s), bind_front<f>(move(s)), and
bind_front<f>(as_const(s)) produce the same type.
Additionally, using specialized structs reduces the size of the resulting functor
in certain scenarios (see PR).
For the zero-argument case, the function still returns a _Bind_fn_t<f>. Since this
type is already a perfect forwarding call wrapper, it yields the same result as
_Bind_front_t<_Bind_fn_t<f>>.
A consequence of this change is that the types returned by bind_front<f>(args...)
and bind_back<f>(args...) are no longer structural - they are not required to be
structural by the standard.
PR libstdc++/122032
libstdc++-v3/ChangeLog:
* include/std/functional (std::bind_front<f>, std::bind_back<f>):
Define in terms of _Bind_front_t/_Bind_back_t.
* testsuite/20_util/function_objects/bind_back/nttp.cc: New tests.
* testsuite/20_util/function_objects/bind_front/nttp.cc: New tests.
Reviewed-by: Patrick Palka <ppalka@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
The std::is_assignable check should test for assignment to an lvalue,
not an rvalue.
libstdc++-v3/ChangeLog:
PR libstdc++/122661
* include/bits/forward_list.h (forward_list::assign(I, I)): Fix
value category in is_assignable check.
* testsuite/23_containers/forward_list/modifiers/122661.cc:
New test.
SIG_IGN also needs to be defined according to the C++ standard.
This was missing in the test.
* testsuite/18_support/headers/csignal/macros.cc: Check for
SIG_IGN.
Signed-off-by: Xavier Bonaventura <xavibonaventura@gmail.com>
"long long" and "unsigned long long" min and max macros were added in
C++11, but they were not present in the climits test.
libstdc++-v3/ChangeLog:
* testsuite/18_support/headers/climits/values.cc: Check for
LLONG_MIN, LLONG_MAX, and ULLONG_MAX.
Signed-off-by: Xavier Bonaventura <xavibonaventura@gmail.com>
This implements P3913R1: Optimize for std::optional in range adaptors.
Specifically, for an opt of type optional<T> that is a view:
* views::reverse(opt), views::take(opt, n), and views::drop(opt, n) returns
optional<T>.
* views::as_const(opt), optional<T&> is converted into optional<const T&>.
optional<T const> is not used in the non-reference case because, such
type is not move assignable, and thus not a view.
libstdc++-v3/ChangeLog:
* include/std/optional (__is_optional_ref): Define.
* include/std/ranges (_Take::operator(), _Drop::operator())
(_Reverse::operator()): Handle optional<T> that are view.
(_AsConst::operator()): Handle optional<T&>.
* testsuite/20_util/optional/range.cc: New tests.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
For non-templated tests, a volatile_<T> alias is used. This alias expands to
volatile T if std::atomic_ref<T>::is_always_lock_free is true, and to T
otherwise. For templated functions, testing is controlled using if constexpr.
PR libstdc++/115402
PR libstdc++/122584
libstdc++-v3/ChangeLog:
* testsuite/29_atomics/atomic_ref/address.cc: Guard test for
volatile with if constexpr.
* testsuite/29_atomics/atomic_ref/deduction.cc: Likewise.
* testsuite/29_atomics/atomic_ref/op_support.cc: Likewise.
* testsuite/29_atomics/atomic_ref/requirements.cc: Likewise.
* testsuite/29_atomics/atomic_ref/bool.cc: Use volatile_t alias.
* testsuite/29_atomics/atomic_ref/generic.cc: Likewise.
* testsuite/29_atomics/atomic_ref/integral.cc: Likewise.
* testsuite/29_atomics/atomic_ref/pointer.cc: Likewise.
* testsuite/29_atomics/atomic_ref/float.cc: Likewise, and remove
not discarding if constexpr.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
This implements proposed resolution for LWG4308 [1].
For T denoting either function type or unbounded array, the optional<T&> no
longer exposes iterator, and viable begin/end members. The conditionally
provided iterator type, it is now defined in __optional_ref_base
base class.
Furthermore, range support for optional<T&> is now also guarded by
__cpp_lib_optional_range_support.
[1] https://cplusplus.github.io/LWG/issue4308
PR libstdc++/122396
libstdc++-v3/ChangeLog:
* include/std/optional (__optional_ref_base): Define.
(std::optional<_Tp&>): Inherit from __optional_ref_base<_Tp>.
(optional<_Tp&>::iterator): Move to base class.
(optional<_Tp&>::begin, optional<_Tp&>::end): Use deduced return
type and constrain accordingly.
* testsuite/20_util/optional/range.cc: Add test for optional<T&>.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
I needed to add module context to dg-prune for libstdc++, and figured it
made sense to sync it with the GCC version rather than maintain slightly
different approaches to stripping the same messages.
libstdc++-v3/ChangeLog:
* testsuite/lib/prune.exp: Sync with gcc prune.exp.
The approved P3778R0 wording doesn't have type_order<_Tp, _Up>::type, so
this patch removes it.
2025-11-10 Jakub Jelinek <jakub@redhat.com>
* libsupc++/compare: Implement final wording of C++26 P3778R0 - Fix
for type_order template definition.
(std::type_order): Remove type member.
Since the implementation namespaces __detail and __exception_ptr aren't
exported from std, ADL can't find these functions there. Adding friend
declarations makes it work.
libstdc++-v3/ChangeLog:
* include/bits/quoted_string.h: Add ADL friends.
* libsupc++/exception_ptr.h: Add ADL friend.
Messing with macros before possibly importing the stdc++.h header unit is
bad form; better to mess with (other) macros afterward.
libstdc++-v3/ChangeLog:
* src/c++23/std.cc.in: Move TBB macro shenanigans after
bits/stdc++.h.
<cassert> isn't suitable for a header unit, because by design it depends on
the user NDEBUG macro. So let's not include it in <bits/stdc++.h>.
libstdc++-v3/ChangeLog:
* include/precompiled/stdc++.h: Remove <cassert>.
* testsuite/util/exception/safety.h: Add <cassert>.
* testsuite/17_intro/headers/c++1998/stdc++_assert_neg.cc:
Don't define _GLIBCXX_NO_ASSERT.
In r15-3499 I added attributes to _Ios_Openmode to avoid -Wswitch false
positives; let's do the same for the other enums in ios_base.
It also seems to me that with these attributes, the tests don't need to
include the end/max/min cases.
libstdc++-v3/ChangeLog:
* include/bits/ios_base.h: Add attribs to _Ios_Fmtflags,
_Ios_Iostate, _ios_seekdir.
* testsuite/27_io/ios_base/types/fmtflags/case_label.cc: Remove
unneeded cases.
* testsuite/27_io/ios_base/types/iostate/case_label.cc: Likewise.
* testsuite/27_io/ios_base/types/openmode/case_label.cc: Likewise.
* testsuite/27_io/ios_base/types/seekdir/case_label.cc: Likewise.
These exports didn't get uncommented when the functionality was implemented.
libstdc++-v3/ChangeLog:
* src/c++23/std.cc.in: Uncomment usings for vprint_*_buffered.
The following patch attempts to implement the library side of the
C++23 P2674R1 paper. As mentioned in the paper, since CWG2605
the trait isn't really implementable purely on the library side.
The compiler side has been committed earlier, so this just uses
the new builtin trait on the library side.
2025-10-30 Jakub Jelinek <jakub@redhat.com>
* include/bits/version.def (is_implicit_lifetime): New.
* include/bits/version.h: Regenerate.
* include/std/type_traits (std::is_implicit_lifetime,
std::is_implicit_lifetime_v): New trait.
* src/c++23/std.cc.in (std::is_implicit_lifetime,
std::is_implicit_lifetime_v): Export.
* testsuite/20_util/is_implicit_lifetime/version.cc: New test.
* testsuite/20_util/is_implicit_lifetime/value.cc: New test.