summaryrefslogtreecommitdiff
path: root/libcxx/include
AgeCommit message (Collapse)Author
2025-11-22[libc++][any] Applied `[[nodiscard]]` (#168826)Hristo Hristov
`[[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
2025-11-21[libc++] Revert fstream::read optimizations (#168894)Jordan Rupprecht
This causes various runtime failures, as reported in #168628. This reverts both #165223 and #167779
2025-11-21[libc++] Optimize std::has_single_bit (#133063)Alcaro
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.)
2025-11-20[libc++][memory] Applied `[[nodiscard]]` to smart pointers (#168483)Hristo Hristov
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>
2025-11-19[libc++] Remove is_signed<T> use from <limits> (#168334)Nikolas Klauser
`numeric_limits` already has an `is_signed` member. We can use that instead of using `std::is_signed`.
2025-11-19[libc++] Make views::iota aware of __int128 (#167869)Nikolas Klauser
Fixes #167991
2025-11-18[libc++] Fix header deprecations (#163356)Nikolas Klauser
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.
2025-11-18[libc++][span] Mark functions as `[[nodiscard]]` (#168033)Hristo Hristov
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>
2025-11-17[libc++] Fix __hash_table::erase(iterator, iterator) to update the bucket ↵Nikolas Klauser
list correctly when erasing the last bucket (#167865) Fixes #167820
2025-11-17[libc++] Refactor basic_string::__recommend (#162631)Nikolas Klauser
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
2025-11-15[libc++] Make `std::numeric_limits<NonPromoted>::traps` `false` (#166724)A. Jiang
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.
2025-11-15[libc++] Apply `[[nodiscard]]` to `in/out_ptr` (#167097)Hristo Hristov
...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>
2025-11-14[libc++][hardening] Allow setting the assertion semantic via CMake. (#167636)Konstantin Varlamov
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`.
2025-11-14[libc++] proper guarding for locale usage in filesystem on Windows (#165470)moleium
- Resolves build issues when localization support is disabled on Windows. - Resolves dependencies on localization in filesystem header implementations. Related PR #164602 Fixes #164074
2025-11-13[libcxx] Fix xsgetn in basic_filebuf (#167779)Michael Jones
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.
2025-11-13[libc++] Merge is_{,un}bounded_array.h into is_array.h (#167479)Nikolas Klauser
These headers are incredibly simple and closely related, so this merges them into a single one.
2025-11-13[libc++] Add an initial modulemap for the test support headers (#162800)Nikolas Klauser
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.
2025-11-13[libc++] Simplify the implementation of the unique_ptr -> shared_ptr ↵Nikolas Klauser
converting constructor (#165619) This also backports LWG2415 as a drive-by.
2025-11-13[libc++] Implement our own is{,x}digit functions for the C locale (#165467)Nikolas Klauser
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.
2025-11-12[libc++] Simplify the implementation of aligned_storage (#162459)Nikolas Klauser
2025-11-12[libc++] Optimize __tree copy/move constructor/assignment with allocator ↵Nikolas Klauser
(#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% ```
2025-11-12[libc++] Mark string functions as [[nodiscard]] (#166524)Nikolas Klauser
This applies `[[nodiscard]]` according to our coding guidelines to `basic_string`.
2025-11-12[libc++] Use variable templates in is_floating_point (#167141)Nikolas Klauser
2025-11-12[libc++] Implement P2988R12: `std::optional<T&>` (#155202)William Tran-Viet
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
2025-11-11[libc++] Remove <stdbool.h> (#164595)Nikolas Klauser
`<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.
2025-11-11[libc++] Remove __is_replaceable emulation (#167355)Louis Dionne
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.
2025-11-11[libc++] Remove some of the uses of aligned_storage inside the library (#161635)Nikolas Klauser
`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.
2025-11-10[libc++] Inline vector::__append into resize (#162086)Nikolas Klauser
These functions are only used in a single place, so there is not much reason to keep them around.
2025-11-10[libc++] Split macros related to hardening into their own header (#167069)Louis Dionne
Hardening macros are easy to extract into their own header, and doing so decreases the complexity of the main __config file.
2025-11-10[libc++] Avoid overloaded `operator,` for (`T`, `Iter`) cases (#161049)A. Jiang
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`.
2025-11-10[libc++] Merge insert/emplace(const_iterator, Args...) implementations (#166470)Nikolas Klauser
2025-11-10[libc++] Replace __libcpp_is_final with a variable template (#167137)Nikolas Klauser
2025-11-10[libc++] Replace the last uses of __tuple_types with __type_list (#167214)Nikolas Klauser
`__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.
2025-11-09[libc++][numeric] Marked saturation artithmetic functions as `[[nodiscard]]` ↵Hristo Hristov
(#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>
2025-11-09[libc++] Treat P0513R0 as a defect report against C++11 (#166690)A. Jiang
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.
2025-11-07[libc++] Optimize fstream::read (#165223)Nikolas Klauser
``` Benchmark old new Difference % Difference ----------- -------- -------- ------------ -------------- bm_read 2468.45 736.27 -1732.18 -70.17% ```
2025-11-07[libc++] Simplify most of the segmented iterator optimizations (#164797)Nikolas Klauser
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.
2025-11-06[libcxx] Implement C++20 std::chrono::is_clock, std::chrono::is_clock_v ↵Yuxuan Chen
(#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.
2025-11-05[libc++][NFC] Make __type_info_implementations a namespace (#166339)Nikolas Klauser
There doesn't seem much of a reason why this should be a struct. Make it a namespace instead.
2025-11-05[libc++] Remove <cstdlib> include from <exception> (#166340)Nikolas Klauser
2025-11-05[libc++] Remove guards for builtins for reference binding traits (#166288)A. Jiang
We're only supporting Clang 20+ and Apple Clang 17 now, where these builtins are universally implemented.
2025-11-04[libc++] Use saturation builtins directly for {add,sub}_sat (#165228)Nikolas Klauser
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.
2025-11-03[libc++] Add move constructor & assignment to `exception_ptr` (#164281)Adrian Vogelsgesang
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
2025-11-03[libcxx] Remove Redundant Reset in ~basic_string (#164718)Aiden Grossman
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.
2025-11-03[libc++] Merge basic_string::__{replace,reset}_internal_buffer (#165404)Nikolas Klauser
2025-11-03[libc++] Simplify the implementation of __formatter::__fill a bit (#147777)Nikolas Klauser
This replaces some SFINAE with `if constexpr`.
2025-11-03[libcxx][modules] Fix missing includes for windows (#158781)Matt
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 {}; | ^ ```
2025-11-02[libc++] Add availability markup for LLVM 19 and LLVM 20 (#140072)Louis Dionne
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.
2025-11-02[libc++] P2641R4: Checking if a `union` alternative is active ↵Nikolas Klauser
(`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>
2025-11-02[libc++] Remove a few unused includes (#165687)Nikolas Klauser