| Age | Commit message (Collapse) | Author |
|
`[[nodiscard]]` should be applied to functions where discarding the
return value is most likely a correctness issue.
-
https://libcxx.llvm.org/CodingGuidelines.html#apply-nodiscard-where-relevant
|
|
This causes various runtime failures, as reported in #168628.
This reverts both #165223 and #167779
|
|
Clang translates most implementations of has_single_bit to `(v ^ (v-1))
> v-1` - except the one definition libc++ actually uses.
Proof of correctness: https://godbolt.org/z/d61bxW4r1
(Could also be fixed by teaching Clang to optimize better, but making
source match output feels clearer to me. And it improves unoptimized
performance.)
|
|
Applied `[[nodiscard]]` where relevant to smart pointers and related
functions.
- [x] - `std::unique_ptr`
- [x] - `std::shared_ptr`
- [x] - `std::weak_ptr`
See guidelines:
-
https://libcxx.llvm.org/CodingGuidelines.html#apply-nodiscard-where-relevant
- `[[nodiscard]]` should be applied to functions where discarding the
return value is most likely a correctness issue. For example a locking
constructor in unique_lock.
---------
Co-authored-by: Hristo Hristov <zingam@outlook.com>
|
|
`numeric_limits` already has an `is_signed` member. We can use that
instead of using `std::is_signed`.
|
|
Fixes #167991
|
|
Currently, there are no diagnostics issued when including a deprecated
header, since the diagnostic is issued inside a system header. This
patch fixes that by using `#warning` instead, which also simplifies the
implementation of the deprecation warnings.
|
|
https://libcxx.llvm.org/CodingGuidelines.html#apply-nodiscard-where-relevant
---------
Co-authored-by: Hristo Hristov <zingam@outlook.com>
Co-authored-by: Nikolas Klauser <nikolasklauser@berlin.de>
|
|
list correctly when erasing the last bucket (#167865)
Fixes #167820
|
|
This does a couple of things:
- code that is only useful for `shrink_to_fit` is moved into that
function
- `shrink_to_fit` is simplified a bit
- `__recommend` is renamed to better reflect what the function actually
does
- `__allocate_long_buffer` asserts that the passed capacity doesn't fit
into the SSO
|
|
Per [LWG554](https://cplusplus.github.io/LWG/issue554), the rationale is
that even if `true / false` traps, the values causing trap are the
converted `int` values produced by usual arithmetic conversion, but not
the original `bool` values.
This is also true for all other non-promoted integer types. As a result,
`std::numeric_limits<I>` should be `false` if `I` is a non non-promoted
integer type.
Fixes #166053.
|
|
...according to Coding Guidelines: `[[nodiscard]]` should be applied to
functions where discarding the return value is most likely a correctness
issue.
Changes to:
- [x] `inout_ptr()`
- [x] `out_ptr()`
At the time of impelentation the `[[nodiscard]]` policy has not been
established yet.
---------
Co-authored-by: Hristo Hristov <zingam@outlook.com>
|
|
Add a new CMake variable, `LIBCXX_ASSERTION_SEMANTIC`, that largely
mirrors `LIBCXX_HARDENING_MODE`, except that it also supports a
special value `hardening_dependent` that indicates the semantic will be
selected based on the hardening mode in effect:
- `fast` and `extensive` map to `quick_enforce`;
- `debug` maps to `enforce`.
|
|
- Resolves build issues when localization support is disabled on
Windows.
- Resolves dependencies on localization in filesystem header
implementations.
Related PR #164602
Fixes #164074
|
|
The optimized version of xsgetn for basic_filebuf added in #165223 has
an issue where if the reads come from both the buffer and the
filesystem it returns the wrong number of characters. This patch should
address the issue.
|
|
These headers are incredibly simple and closely related, so this merges
them into a single one.
|
|
This should improve the time it takes to run the test suite a bit. Right
now there are only a handful of headers in the modulemap because we're
missing a lot of includes in the tests. New headers should be added
there from the start, and we should fill up the modulemap over time
until it contains all the test support headers.
|
|
converting constructor (#165619)
This also backports LWG2415 as a drive-by.
|
|
The C locale is defined by the C standard, so we know exactly which
digits classify as (x)digits. Instead of going through the locale base
API we can simply implement functions which determine whether a
character is one ourselves, and probably improve codegen significantly
as well that way.
|
|
|
|
(#163558)
This patch applies the same optimization as implemented in #151304 to
the overloads taking an allocator as the second argument.
Apple M4:
```
Benchmark old new Difference % Difference
----------------------------------------------------------- -------------- -------------- ------------ --------------
std::map<int,_int>::ctor(&&,_different_allocs)/0 14.59 12.78 -1.81 -12.41%
std::map<int,_int>::ctor(&&,_different_allocs)/1024 16407.05 6265.11 -10141.94 -61.81%
std::map<int,_int>::ctor(&&,_different_allocs)/32 395.99 199.76 -196.23 -49.56%
std::map<int,_int>::ctor(&&,_different_allocs)/8192 141478.67 53767.84 -87710.83 -62.00%
std::map<int,_int>::ctor(const&,_alloc)/0 12.83 12.71 -0.12 -0.94%
std::map<int,_int>::ctor(const&,_alloc)/1024 9979.71 7849.11 -2130.59 -21.35%
std::map<int,_int>::ctor(const&,_alloc)/32 283.82 266.05 -17.77 -6.26%
std::map<int,_int>::ctor(const&,_alloc)/8192 81418.63 63190.41 -18228.21 -22.39%
std::map<std::string,_int>::ctor(&&,_different_allocs)/0 14.58 12.68 -1.90 -13.00%
std::map<std::string,_int>::ctor(&&,_different_allocs)/1024 19513.56 7806.04 -11707.52 -60.00%
std::map<std::string,_int>::ctor(&&,_different_allocs)/32 477.80 247.28 -230.52 -48.25%
std::map<std::string,_int>::ctor(&&,_different_allocs)/8192 504558.78 69592.21 -434966.56 -86.21%
std::map<std::string,_int>::ctor(const&,_alloc)/0 12.64 12.60 -0.04 -0.33%
std::map<std::string,_int>::ctor(const&,_alloc)/1024 43198.53 37220.54 -5977.99 -13.84%
std::map<std::string,_int>::ctor(const&,_alloc)/32 928.39 867.03 -61.36 -6.61%
std::map<std::string,_int>::ctor(const&,_alloc)/8192 461313.81 389200.82 -72112.99 -15.63%
```
|
|
This applies `[[nodiscard]]` according to our coding guidelines to
`basic_string`.
|
|
|
|
Resolves #148131
- Unlock `std::optional<T&>` implementation
- Allow instantiations of `optional<T(&)(...)>` and `optional<T(&)[]>`
but disables `value_or()` and `optional::iterator` + all `iterator`
related functions
- Update documentation
- Update tests
|
|
`<stdbool.h>` is provided by the compiler and both Clang and GCC provide
C++-aware versions of these headers, making our own wrapper header
entirely unnecessary.
|
|
The Trivial Relocation feature has been removed from the C++26 working
draft. Based on discussions in Kona, it is unlikely that the
"replaceable" type concept will come back in the C++29 time frame.
Since we don't have a use for the type trait in the library at the
moment, remove the code associated to it. If we end up needing something
like it in the future, we can always add it back.
|
|
`aligned_storage` has been deprecated and will most likely be removed in
a future version of C++. This patch removes some of its uses to avoid
having to work around its removal in the future.
|
|
These functions are only used in a single place, so there is not much
reason to keep them around.
|
|
Hardening macros are easy to extract into their own header, and doing so
decreases the complexity of the main __config file.
|
|
Several components in libc++ aren't defending against overloaded
`operator,(T, Iter)` currently. Existing deleted overloads in
`test_iterators.h` are insufficient for such cases.
This PR adds corresponding deleted overloads with reversed order and
fixes these libc++ components.
- `piecewise_linear_distribution`'s iterator pair constructor,
- `piecewise_linear_distribution::param_type`'s iterator pair
constructor,
- `piecewise_constant_distribution`'s iterator pair constructor,
- `piecewise_constant_distribution::param_type`'s iterator pair
constructor,
- `money_get::do_get`,
- `money_put::do_put`, and
- `num_put::do_put`.
|
|
|
|
|
|
`__tuple_types` is at this point just a `__type_list` with a weird name,
so we can just replace the few places it's still used.
|
|
(#166898)
...according to Coding Guidelines: *`[[nodiscard]]` should be applied to
functions where discarding the return value is most likely a correctness
issue.*
# References
-
https://libcxx.llvm.org/CodingGuidelines.html#apply-nodiscard-where-relevant
-
https://github.com/llvm/llvm-project/pull/166524#issuecomment-3495567876
Co-authored-by: Hristo Hristov <zingam@outlook.com>
|
|
P0513R0 is essentially a collective resolution paper of LWG2543,
LWG2791, LWG2809, and LWG2817.
Among these LWG issues, LWG2543 (conditionally enabled `hash`) and
LWG2817 (`hash<nullptr_t>`) affect pre-C++17 utilities. We generally
backport changes from LWG issues, so this patch backports the relevant
parts of P0513R0.
Although we provide `hash<unique_ptr>` as an extension in C++03 mode, as
C++03 mode isn't encouraged now, this patch leaves `hash<unique_ptr>`
unchanged in C++03 mode.
|
|
```
Benchmark old new Difference % Difference
----------- -------- -------- ------------ --------------
bm_read 2468.45 736.27 -1732.18 -70.17%
```
|
|
This patch does two things.
(1) It replaces SFINAE with `if constexpr`, avoiding some overload
resolution and unnecessary boilerplate.
(2) It removes an overload from `__for_each_n` to forward to
`__for_each`, since `__for_each` doesn't provide any further
optimizations.
|
|
(#160607)
Implemented
[[*time.traits.is.clock*]](https://eel.is/c++draft/time.traits.is.clock)
from [P0355R7](https://wg21.link/p0355r7).
This patch implements the C++20 feature `is_clock` and `is_clock_v`
based on the documentation [on
cppreference](https://en.cppreference.com/w/cpp/chrono/is_clock.html)
Fixes #166049.
|
|
There doesn't seem much of a reason why this should be a struct. Make it
a namespace instead.
|
|
|
|
We're only supporting Clang 20+ and Apple Clang 17 now, where these
builtins are universally implemented.
|
|
This doesn't improve performance (except with optimizations disabled),
since the compiler is able to fold our current implementation. However,
it does significantly reduce the amount of code the compiler has to sift
through, reducing compile times a bit.
|
|
This commit adds move constructor, move assignment and `swap`
to `exception_ptr`. Adding those operators allows us to avoid
unnecessary calls to `__cxa_{inc,dec}rement_refcount`.
Performance results (from libc++'s CI):
```
Benchmark Baseline Candidate Difference % Difference
------------------------------------ ---------- ----------- ------------ --------------
bm_exception_ptr_copy_assign_nonnull 9.77 9.94 0.18 1.79%
bm_exception_ptr_copy_assign_null 10.29 10.65 0.35 3.42%
bm_exception_ptr_copy_ctor_nonnull 7.02 7.01 -0.01 -0.13%
bm_exception_ptr_copy_ctor_null 10.54 10.60 0.06 0.56%
bm_exception_ptr_move_assign_nonnull 16.92 13.76 -3.16 -18.70%
bm_exception_ptr_move_assign_null 10.61 10.76 0.14 1.36%
bm_exception_ptr_move_ctor_nonnull 13.31 10.25 -3.06 -23.02%
bm_exception_ptr_move_ctor_null 10.28 7.30 -2.98 -28.95%
bm_exception_ptr_swap_nonnull 19.22 0.63 -18.59 -96.74%
bm_exception_ptr_swap_null 20.02 7.79 -12.23 -61.07%
```
As expected, the `bm_exception_ptr_copy_*` benchmarks are not influenced by
this change. `bm_exception_ptr_move_*` benefits between 18% and 30%. The
`bm_exception_ptr_swap_*` tests show the biggest improvements since multiple
calls to the copy constructor are replaced by a simple pointer swap.
While `bm_exception_ptr_move_assign_null` did not show a regression in the CI
measurements, local measurements showed a regression from 3.98 to 4.71, i.e. by
18%. This is due to the additional `__tmp` inside `operator=`. The destructor
of `__other` is a no-op after the move because `__other.__ptr` will be a
nullptr. However, the compiler does not realize this, since the destructor is
not inlined and is lacking a fast-path. As such, the swap-based implementation
leads to an additional destructor call. `bm_exception_ptr_move_assign_nonnull`
still benefits because the swap-based move constructor avoids unnecessary
__cxa_{in,de}crement_refcount calls. As soon as we inline the destructor, this
regression should disappear again.
Works towards #44892
|
|
8dae17be2991cd7f0d7fd9aa5aecd064520a14f6 refactors basic_string for more
code reuse. This makes sense in most cases, but has performance overhead
in the case of ~basic_string. The refactoring of ~basic_string to call
__reset_internal_buffer() added a redundant (inside the destructor)
reset of the object, which the optimizer is unable to optimize away in
many cases. This patch prevents a ~1% regression we observed on an
internal workload when applying the original refactoring. This does
slightly pessimize the code readability, but I think this change is
worth it given the performance impact.
I'm hoping to add a benchmark(s) to the upstream libc++ benchmark suite
around string construction/destruction to ensure that this case does not
regress as it seems common in real world applications. I will put up a
separate PR for that when I figure out a reasonable way to write it.
|
|
|
|
This replaces some SFINAE with `if constexpr`.
|
|
Previously, I was getting the following error when attempting to compile
libc++ on windows with modules enabled.
```
While building module 'std':
In file included from <module-includes>:1:
In file included from gen/third_party/libc++/src/include/algorithm:1865:
In file included from gen/third_party/libc++/src/include/__algorithm/inplace_merge.h:28:
In file included from gen/third_party/libc++/src/include/__memory/unique_temporary_buffer.h:17:
In file included from gen/third_party/libc++/src/include/__memory/allocator.h:19:
gen/third_party/libc++/src/include/__new/allocate.h(40,73): error:
declaration of 'align_val_t' must be imported from module
'sys_stage1.sysroot_vcruntime_new_h' before it is required
40 | return static_cast<_Tp*>(__builtin_operator_new(__size, static_cast<align_val...
| ^
../../third_party/depot_tools/win_toolchain/vs_files/e4305f407e/VC/Tools/MSVC/14.44.35207/include/vcruntime_new.h(27,33): note:
declaration here is not visible
27 | _VCRT_EXPORT_STD enum class align_val_t : size_t {};
| ^
```
|
|
An LLVM 19-aligned libc++ was released with macOS 15.4 (and corresponding OSes),
and LLVM-20 aligned with macOS 26.0. This patch adds availability markup to
reflect that.
|
|
(`std::is_within_lifetime`) (#165243)
<https://wg21.link/P2641R4>
Implements the C++26 function in `<type_traits>` [meta.const.eval] (and
the corresponding feature test macro `__cpp_lib_is_within_lifetime`)
```c++
template<class T>
consteval bool is_within_lifetime(const T*) noexcept;
```
This is done with the `__builtin_is_within_lifetime` builtin added to
Clang 20 by #91895 / 2a07509c8d3c8b5b2c88e4f73dde0071bf506870. This is
not (currently) available with GCC.
This implementation has provisions for LWG4138
<https://cplusplus.github.io/LWG/issue4138> where it is ill-formed to
instantiate `is_within_lifetime<T>` with a function type `T`.
Closes #105381
Co-authored-by: Mital Ashok <mital@mitalashok.co.uk>
|
|
|