Resolves#186801
Removed the non-standard member type `iterator_type` from `__wrap_iter`.
This member exposed the underlying iterator type, and its removal
prevents users from relying on the implementation detail.
The type `__gnu_cxx::hash_{,multi}map` creates objects of type
`std::pair<Key, Value>` and returns pointers to them of type
`std::pair<const Key, Value>`. If either `Key` or `Value` are
non-standard-layout, this is UB, and is furthermore considered by
pointer field protection to be a type confusion, which leads to a
program crash. Fix it by using the correct type for the pair's storage
and using const_cast to form a pointer to the key in the one place where
that is needed.
Reviewers: ldionne
Reviewed By: ldionne
Pull Request: https://github.com/llvm/llvm-project/pull/183223
Since befaa35212dbaac39cd76a8dc748e4df7c90a0d9, the CI stably failed for
the generic-no-wide-characters build, because in no-`wchar_t` modes, the
header for `__remove_cv_t` wasn't properly included.
This PR adds the missing include of `<__type_traits/remove_cv.h>`.
As drive-by, `<__cstddef/size_t.h>` and
`<__type_traits/is_constant_evaluated.h>`, which are included by
`<cwchar>`, are also made included by `<string>` to avoid potential
regression as we're using `size_t` and
`__libcpp_is_constant_evaluated()` in `<string>`.
The frozen C++03 headers got an invalid simplification in #134045 that
changed the signature of random_shuffle to use a forwarding reference
instead of a lvalue reference. This patch fixes it and adds a test.
---------
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
In `<version>` and test files, `__cpp_lib_destroying_delete` is already
properly guarded with standard modes, so it's redundant to say standard
revision in `test_suite_guard`/`libcxx_guard`.
__is_transparent_v used to accept an additional _Key template argument
whose sole purpose was to make the instantiation as a whole dependent.
It turns out that creates confusion around whether that trait takes into
account the key type (it does not). Instead, we can use our traditional
approach for making template params artificially dependent, which allows
removing the confusing parameter.
For disclaimer, I authored this patch with Claude code just to see if I
could get it to do the right thing. It works, but you have to steer it
right.
Fixes#186417
Renaming from _Tp to _ArgumentType makes it clearer that we're passing
the argument type intended for the comparator, which allows checking
whether *that specific use* of the comparator would be transparent.
Fixes#186396
The check whether a stream is associated with a terminal or not and the
flushing of the stream in `std::print()` is needed only on Windows.
Additionally, the correct flush should be used. When `std::print` is
called with a C stream, `std::fflush()` should be used. When it is
called with C++ `ostream`, `ostream::flush()` should be called.
Because POSIX does not have a separate Unicode API for terminal output,
checking for terminal (`isatty`) and flushing is not needed at all.
Moreover, `isatty` has noticeable performance cost.
See also https://wg21.link/LWG4044.
Fixes#70142
`formatter::parse` and `formatter::format` only have to accept
`basic_format_parse_context` and `basic_format_context` respectively,
which are only guaranteed to be provided via `<format>`. This allows us
to only declare the functions for `formatter<bool>` in `<vector>` and
define them if `<format>` is included. This reduces the amount of time
it takes to parse `<vector>` by ~15% on my system.
When the allocators use fancy pointers, the internal map of `deque`
stores `FancyPtr<T>` objects, and the previous strategy accessed these
objects via `const FancyPtr<const T>` lvalues, which usually caused core
language undefined behavior. Now `const_iterator` stores `FancyPtr<const
FancyPtr<T>>` instead of `FancyPtr<const FancyPtr<const T>>`, and ABI
break can happen when such two types have incompatible layouts.
This is necessary for reducing undefined behavior and `constexpr`
support for `deque` in C++26, and I currently don't want to provide any
way to opt-out of that behavior.
For `iterator`, the current strategy makes it store
`FancyPtr<FancyPtr<T>>`. But it would make more sense to also store
`FancyPtr<const FancyPtr<T>>` because we never modify the map via
`iterator`.
For some pathological combinations of allocators and fancy pointers, the
rebinding trick doesn't work. These cases are rejected by
`static_assert`.
The existing test coverage seems to be sufficient.
- Hoist `operator*()`, `operator->()`, `value()` into their respective
`optional_storage_base` to reduce the amount of concepts flying around.
- `value_or()` has been deliberately left out since that seems to
produce extra (superfluous) error messages during invalid template
instantiation.
- Rename `__optional_iterator` into `__optional_iterator_base` and make
it part of the `__optional_{meow}_base` inheritance chain. This allows
us to get rid of a sketchy-looking downcast and shorten some code.
We currently have an instantiation cycle in `variant`'s comparison
operators. This patch fixes that by replacing a `decltype(auto)` with an
explicit return type, removing the requirement to instantiate the
function in order to know the return type.
Fixes#182232
There is no reason to double-wrap iterators, since we can already
achieve anything we want within `__bounded_iter`itself.
This is technically ABI breaking, but people using bounded iterators
shouldn't require ABI stability currently.
Fixes#178521
The previous `_LIBCPP_ASAN_VOLATILE_WRAPPER` approach was used to
prevent
speculative loads of string data before the short/long state was
determined. This patch replaces that mechanism with a more explicit
`__annotate_memory_barrier()` using an empty volatile assembly block.
This PR is inspired by #183457 and by downstream false positive on
`__get_long_size`. It fails same way as `__get_long_pointer` before we
have
`_LIBCPP_ASAN_VOLATILE_WRAPPER`. Barrier approach avoids
expanding `_LIBCPP_ASAN_VOLATILE_WRAPPER` for size_t, and to
in general looks more readable.
I failed to create reasonable reproducer for test, I suspect it requires
precise set of compiler flags, and libc++ site_config which will be hard
to maintain in test.
Resolves#126442
- Converts all the relevant functions that used `.base()` into friends
- Fixed usage in `<regex>`
---------
Co-authored-by: A. Jiang <de34@live.cn>
`std::__to_address(__get_pointer())` is an extremely common pattern
inside `string` and is basically equivalent to `data()`, except that
`data()` only returns a non-const pointer since C++17. This patch
introduces `__data()` to back-port returning a non-const pointer.
Currently `vector::append_range` grows even when appending a number of
elements that is exactly equal to its spare capacity, which is
guaranteed by the standard to _not_ happen.
Fixes#183256
In #155245, we implemented an optimization to std::map and std::set
search operations. That optimization took advantage of something that is
guaranteed by the Standard, namely that the comparator provided to the
associative container is a valid strict weak ordering.
Sadly, some code in the wild did not satisfy this requirement, such as
Boost.ICL: boostorg/icl#51
Since this can have extremely tricky runtime consequences, this patch
introduces a temporary escape hatch for the LLVM 22 release that allows
reverting to the previous behavior. It also explicitly calls out the
change in the release notes, adds some regression tests and adds debug
mode support for catching some of these invalid predicates.
Fixes#183189
Libc++ currently redeclares ::lgamma_r on platforms that provide it.
This causes issues when building with modules, and redeclaring functions
provided by another library (here the C library) is bad hygiene.
Instead, use an asm declaration to call the right function without
having to redeclare it.
- The Standard wording in https://eel.is/c++draft/time.format#13 is similar
to TAI formatting in that it's equivalent to formatting a `sys_time`
with a fixed offset. Leap seconds should not be considered.
- Tests need to be adjusted by adding the number of leap seconds between
the GPS epoch and the tested date, which is 15s for 2010 and 18s for
2019.
- The TAI and GPS tests using `meow_time<cr::duration<long, ...>>`
should use `long long` because the offset swill overflow a 32-bit
signed integer.
This patch moves `format_kind` to `<__fwd/format.h>` and moves the
mandate of `basic_format_context` into the class body. This reduces the
time it takes to parse `<optional>` by ~14%.
This PR fixes two issues regarding the alignment of native wait:
- In the internal platform call, the local variable is copied from a
potentially non-aligned buffer
- Under the unstable ABI, the predicate to test eligibility of a type
being able to do native wait is purely on size. We should test also the
alignment of such type is qualified for platform call
---------
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
I noticed that the various `_LIBCPP_INTRODUCED_IN_LLVM_<ver>` usages in
`availability.h` were defined a bit all over the place. I think it'd
make the most sense to sort them in reverse chronological order (like
their definitions).
We already have `_PairT`, which is just a pair of two `size_t`s, so we
might as well use that throughout the file. This avoids the `pair`
include altogether, reducing header parse times a bit in some cases.
We're currently unwrapping `less<T>` even if the `key_type` isn't `T`.
This causes the removal of an implicit conversion to `const T&` if the
types mismatch. Making `less<T>` transparent in that case changes
overload resolution and makes it fail potentially.
Fixes#179319
To reduce the noise in #134330 for `libcxx/include/__tree`, we migrate
from certain `static_cast` to `std::__static_fancy_pointer_cast` in this
separate patch.
This change is needed to properly work with fancy pointers like
`min_pointer` during constant evaluation for `std::map`
Co-authored-by: Joseph Huber <huberjn@outlook.com>