Commit Graph

13354 Commits

Author SHA1 Message Date
Martin Storsjö
76dba2ea02 [libcxx] Fix a comment link for the unicode NBSP char. NFC. (#139692) 2025-05-14 00:11:02 +03:00
Roland McGrath
81b20e110b [libc++] Work around new GCC 15 type_traits builtins that can't be used as Clang's can (#137871)
GCC 15 has added builtins for various C++ type traits that Clang
already had.  Since `__has_builtin(...)` now finds these, the #if
branches previously only used for Clang are now used for GCC 15.
However, GCC 15 requires that these builtins only be used in type
aliases, not in template aliases.

For now, just don't use the `__has_builtin(...)` branches under newer
GCC versions, so both 14 and 15 work during the transition.  This
can be cleaned up later to use all the GCC 15 builtins available.

Fixed: #137704
Fixed: #117319
2025-05-13 12:23:50 -07:00
A. Jiang
ab60910e01 [libc++][format] Discard contents since null-terminator in character arrays in formatting (#116571)
Currently, built-in `char`/`wchar_t` arrays are assumed to be
null-terminated sequence with the terminator being the last element in
formatting. This doesn't conform to [format.arg]/6.9.

> otherwise, if `decay_t<TD>` is `char_type*` or `const char_type*`,
> initializes value with `static_cast<const char_type*>(v)`;

The standard wording specifies that character arrays are decayed to
pointers. When the null terminator is not the last element or there's no
null terminator (the latter case is UB), libc++ currently produces
different results.

Also fixes and hardens `formatter<CharT[N], CharT>::format` in
`<__format/formatter_string.h>`. These specializations are rarely used.

Fixes #115935. Also checks the preconditions in this case, which fixes
#116570.
2025-05-12 16:49:25 -04:00
Nikolas Klauser
c8f2cdafd4 [libc++] Simplify the implementation of std::get for pairs (#114984)
This makes it clearer what the functions actually do. As a nice
side-effect it also avoids a function call. If the C++03 header split is
successful we could drop `__get_pair` entirely.
2025-05-12 22:40:17 +02:00
Matt
769c6a95ae [libc++] Fix missing #includes (#130536)
Adds missing includes that were detected when I tried to build libc++ as
a module.

Working towards #127012
2025-05-12 16:36:10 -04:00
halbi2
5e94e26a7a [libc++] Improve test coverage for containers' scary.pass.cpp (#131550) 2025-05-12 16:35:05 -04:00
Martin Licht
608c85cb02 [libc++] Documentation polish (#132962)
- Some lists re-ordered alphabetically
- Spelling, grammar, language, etc
2025-05-12 16:23:31 -04:00
Raul Tambre
fc3b67aee8 [cmake] Normalize TARGET_SUBDIR paths (#138524)
Some code paths normalize ".." and thus don't create the directory. But some execute in a
shell thus requiring the directory to exist to be able to take the parent directory.

This patch normalizes all the `TARGET_SUBDIR` variables to avoid this issue.
2025-05-12 15:59:39 -04:00
Stephan Bergmann
b233c5fbe0 [libc++] Fix use of std::errc() for C++ < 11 (#138522)
After 8fc2538f33 "Reapply '[libc++]
Optimize num_put integral functions' (#131613) (#133572)", including
<locale> in C++03 mode with Debug hardening enabled fails.

This patch fixes that by applying a workaround used elsewhere to
construct errc in C++03 mode.
2025-05-12 15:55:24 -04:00
Nikolas Klauser
ab65e4a730 [libc++] Fix disabling of extension warnings in C++20 and later (#134989)
`__has_feature(modules)` is always true in C++20 and later. Instead of
using that, just disable extension warnings if they're not ignored
through the system header machinery anyways.
2025-05-10 17:05:35 +02:00
Nikolas Klauser
df78e288c3 [libc++] Use __is_address_in_range in vector (#139032)
This avoids a branch in `vector`s code on whether we're constant
evaluating, which improves our coverage of constant-evaluated code.
2025-05-09 21:45:32 +02:00
Petr Hosek
25a03c1c7c [libcxx][NFC] Use macros for functions that support overriding detection (#133876)
We plan to replace the existing mechanism for overriding detection with
one that doesn't require the use of a special section as an alternative
to llvm/llvm-project#120805 which had other downsides.

This change is a pure refactoring that lays the foundation for a
subsequent change that will introduce the new detection mechanism.
2025-05-09 11:25:14 -07:00
Nikolas Klauser
948bffa951 [libc++] Simplify __promote (#136101)
This avoids instantiating an extra class for every variant `__promote`
is used in.
2025-05-08 16:48:57 -04:00
Hui
f39ac3f569 [libc++] Add test for flat_set::insert not creating temporaries (#138387)
Fixes #119016
2025-05-08 16:42:01 -04:00
Louis Dionne
45d493b680 [libc++] Add the __is_replaceable type trait (#132408)
That type trait represents whether move-assigning an object is
equivalent to destroying it and then move-constructing a new one from
the same argument. This will be useful in a few places where we may want
to destroy + construct instead of doing an assignment, in particular
when implementing some container operations in terms of relocation.

This is effectively adding a library emulation of P2786R12's
is_replaceable trait, similarly to what we do for trivial relocation.
Eventually, we can replace this library emulation by the real
compiler-backed trait.

This is building towards #129328.
2025-05-08 16:35:00 -04:00
Aaron Ballman
7548cec16f [www][docs] Remove last mentions of IRC (#139076)
It's the end of an era. The IRC channel was previously where the
community gathered to discuss technical topics but is now a ghost town
where the primary activity is moderators (me) kickbanning the same
individual dozens of times a day for CoC violations and the secondary
activity is telling the occasional person to come to Discord for help.
The number of people engaging on IRC for the community's intended
purposes seems to be roughly one person a month.

So this removes all remaining mentions of IRC from our documentation so
that it no longer appears to be an "official" channel for communicating
with the community. It also removes IRC handles from the various
maintainers lists, since those would stand out as confusing
anachronisms.

The IRC channel topic already recommends people come to the Discord
server. There is no way to "shut down" an IRC channel such that it no
longer exists, so the channel will continue to exist on OFTC, but will
be unmoderated.

(This was previously discussed in https://discourse.llvm.org/c/llvm/5
but some mentions persisted.)
2025-05-08 09:40:33 -04:00
Ryan Prichard
93aba1e240 [libc++][Android] Disable fdsan in filebuf close.pass.cpp (#102412)
fdsan is Bionic's "File Descriptor Sanitizer". Starting in API 30+, it
aborts this close.pass.cpp test, because it closes the FD belonging to
std::filebuf's FILE*. For `__BIONIC__`, disable that part of the test.
2025-05-07 15:27:19 -04:00
yronglin
13c464be84 [libc++] Implement P3379R0 Constrain std::expected equality operators (#135759)
Closes #118135

Co-authored-by: A. Jiang <de34@live.cn>
2025-05-07 15:25:00 -04:00
A. Jiang
fc281e1b4f [libc++][docs] Confirm that P3136R1 Retiring niebloids is Complete (#135932)
As libc++ has been implementing niebloids as CPOs since LLVM 14 due to
https://reviews.llvm.org/D116570.

Also changes some comments in test files to use the formal term
"algorithm function object".

Closes #118133.
2025-05-07 15:20:43 -04:00
Dan Katz
f0ba3ac32b Merge branch 'p2996' into wip 2025-05-07 13:30:48 -04:00
Louis Dionne
91074a1b50 [libc++] Reword release note section about future releases (#138544)
For several releases, we had a section in the release notes that was
called "Upcoming Deprecations and Removals". That section was used to
advertize breaking changes in future releases as opposed to ones in the
current release.

However, the way this section was worded and organized made it unclear
what release these announcements related to. This patch rewords that
section of the release notes to make it less ambiguous and moves items
that aren't done yet (but relate to the ongoing release) to a different
section with a TODO.
2025-05-07 13:01:40 -04:00
Louis Dionne
e33ca9adc8 [libc++] Reword std::advance assertion message for consistency with ranges::advance (#138749)
As brought up in https://github.com/llvm/llvm-project/pull/133276.
2025-05-07 12:59:38 -04:00
Nikolas Klauser
38595fb257 [libc++] Remove a few unnecessary branches from basic_string::find (#137266)
I've recently looked at the assembly for `basic_string::find()` and
realized that there were a few branches I didn't expect. It turns out
that we check for null before calling `__constexpr_memchr` in some
cases, which the compiler doesn't optimize away. This is a really
uncommon case though, so I'm not convinced it makes a ton of sense to
optimize for that.

The second case is where `__pos >= __sz`. There, we can instead check
`__pos > __sz`, which the optimizer is able to remove if `__pos == 0`,
which is also a quite common case (basic_string::find(CharT), without an
explicit size parameter).
2025-05-07 10:54:34 -04:00
Dan Katz
3c580b668b 'underlying_entity_of', 'proxied_entity_of' for new paper. 2025-05-07 10:42:53 -04:00
Nikolas Klauser
ed0aa9961c [libc++] Add _LIBCPP_NO_UNIQUE_ADDRESS to flat_{,multi}map::value_compare (#137594)
This breaks the ABI of `flat_{,multi}map::value_compare`, but this type
has only been introduced in LLVM 20, so it should be very unlikely that
we break anybody if we back-port this now.
2025-05-07 10:09:40 -04:00
Dan Katz
78ee982e44 Fix validation of 'reflect_value' results. 2025-05-07 09:23:38 -04:00
Peng Liu
7087ee6bc7 [libc++][NFC] Improve test readability for std::fill_n (#133771)
This patch enhances test readability by inlining standalone tests,
eliminating unnecessary navigation. Additionally, several classes with
ad-hoc names have been renamed for better clarity:
- `A` -> `CharWrapper` as it wraps a char
- `B -> CharTransformer` as it accepts a char `xc` but stores `xc + 1`
- `Storage -> CharUnionStorage` as it stores a union of 2 `char`s.  

This patch addresses a follow-up comment from #120909 to inline tests.
2025-05-06 16:17:18 -04:00
Nikolas Klauser
f25f9e480b [libc++][NFC] Remove a bunch of redundant ASan existence checks (#128504)
There are currently lots of `_LIBCPP_HAS_ASAN` and
`__libcpp_is_constant_evaluated()` checks which aren't needed, since it
is centrally checked inside `__debug_utils/sanitizers.h`.
2025-05-06 22:16:58 +02:00
A. Jiang
2f54a843bb [libc++][test] Test flat_meow with proper underlying iterators (#131290)
Flat container adaptors require the iterators of underlying containers
to be random access, and it is required that random access container
iterators must support three-way comparison ([container.reqmts]/39 - /41).

As a result, we should at least avoid testing "containers" with random
access but not three-way comparable iterators for flat container
adaptors.

This patch adds a new class template `three_way_random_access_iterator`
to `test_iterators.h` and fixes some usages of `MinSequenceContainer`
with the new iterators.
2025-05-06 16:15:19 -04:00
Raul Tambre
58d4ebb29f [libcxx][CMake] Use the right variable in the C library error message (#138458)
Fixes: 3b78dfa10c
2025-05-06 16:07:49 -04:00
Dan Katz
16f4b13424 Fixes/improvements to 'substitute'. 2025-05-06 15:52:57 -04:00
Louis Dionne
d05ab119e1 [libc++] Remove redundant and somewhat confusing assertions around advance() (#133276)
The std::advance function has a clear precondition that it can only be
called with a negative distance when a bidirectional iterator is used.
However, prev() and next() don't have such preconditions explicitly,
they inherit it from calling advance().

This patch removes assertions in prev() and next() that were duplicates
of similar ones in advance(), and removes a copy-pasted comment that was
trying to justify the use of _LIBCPP_ASSERT_PEDANTIC but IMO is creating
confusion with little benefit.
2025-05-06 15:44:26 -04:00
Louis Dionne
60b43ef70b [libc++] Improve the test coverage for std::vector::emplace (#132440)
This patch refactors the test for std::vector::emplace back to cover new
corner cases, and increase coverage for normal cases as well.

This is building towards #129328.
2025-05-06 15:29:27 -04:00
Louis Dionne
3ea0754d9a [libc++] Enable sized deallocation when building operator new shims on Apple (#134152)
This ensures that we are able to build the shims on compilers that
enable sized deallocation by default and those that don't, regardless.
2025-05-06 15:21:23 -04:00
Dan Katz
d6eeb04705 Merge branch 'main' into wip 2025-05-06 11:30:41 -04:00
Nikolas Klauser
3dc1f759e6 [libc++][C++03] Remove code that is not used in C++03 (#134045)
This patch removes code which is guarded by `_LIBCPP_STD_VER` and
`_LIBCPP_CXX03_LANG`.

This is part of
https://discourse.llvm.org/t/rfc-freezing-c-03-headers-in-libc.
2025-05-06 09:53:56 +02:00
Dan Katz
a11f0d2d14 Fix annotations bug. 2025-05-05 18:13:50 -04:00
Louis Dionne
25fc52e655 [libc++] Re-introduce _LIBCPP_DISABLE_AVAILABILITY (#134158)
The `_LIBCPP_DISABLE_AVAILABILITY` macro was removed in afae1a5f32 as an
intended no-op. It turns out that some projects are making use of that
macro to work around a Clang bug with availability annotations that
still exists: https://github.com/llvm/llvm-project/issues/134151.

Since that Clang bug still hasn't been fixed, I feel that we must sill
honor that unfortunate macro until we've figured out how to get rid of
it without breaking code.
2025-05-05 14:19:13 -07:00
Mark de Wever
46c730656a [libc++][CI] Use latest Docker image. (#132539)
This image was updated in #132271.
Due to issues with upstream packages, it uses #134497 instead.
2025-05-04 18:57:52 +02:00
Dan Katz
fc1480d51f Fix 'bases_of' with aliases. 2025-05-03 16:57:13 -04:00
Nikolas Klauser
8c3aa3e81c [libc++][NFC] Replace typedefs with using declarations in <vector> (#134083)
This brings the code base a bit closer to using `using` declarations
everywhere.
2025-05-03 08:39:48 +02:00
Dan Katz
8c12bec3fa Fixes for dependent entity proxies.
Also fixes a crash in vanilla P2996 involving similar code.
2025-05-02 15:50:01 -04:00
Dan Katz
d5d35efe79 Entity proxies. 2025-05-02 11:09:40 -04:00
Nikolas Klauser
a6459debc0 [libc++] Remove a few unused includes from <__bit/*> (#137934) 2025-05-01 15:02:17 +02:00
Nikolas Klauser
180bc5916b [libc++] Simplify the implementation of is_unbounded_array a bit (#137716) 2025-05-01 15:01:43 +02:00
Dan Katz
90dc2ff8fc 'access_context::current()' is always value dependent. 2025-04-30 14:07:49 -04:00
Hristo Hristov
4ed8f38e81 [libc++][pair] P2944R3: Constrain std::pair's equality operator (#136672)
Implements https://wg21.link/P2944R3 (partially):
- [pairs.spec](https://eel.is/c++draft/pairs.spec)

Related issues:
- Related to #105424
- Related to #118135
  - PR https://github.com/llvm/llvm-project/pull/135759
  - PR https://github.com/llvm/llvm-project/pull/117664

Closes: [#136763](https://github.com/llvm/llvm-project/issues/136763)

# References
- https://eel.is/c++draft/concept.booleantestable
- https://eel.is/c++draft/concept.equalitycomparable

---------

Co-authored-by: Hristo Hristov <zingam@outlook.com>
Co-authored-by: Nikolas Klauser <nikolasklauser@berlin.de>
2025-04-29 22:00:16 +03:00
Nikolas Klauser
e43e8ec7af [libc++] Remove dead implementation of is_nothrow_convertible and merge the remaining code into is_convertible.h (#137717)
We can use the `__is_nothrow_convertible` builtin unconditionally now,
which makes the implementation very simple, so there isn't much of a
need to keep a separate header around.
2025-04-29 08:46:06 +02:00
Mark de Wever
2b57ebb50b [libc++][CI] Improves updating Docker image. (#134497)
This makes it easier to build a new Docker image in the CI. Since the
new image is not used automatically it's safe to commit these changes
directly to main. Then use a PR to test the new image.
2025-04-28 18:51:32 +02:00
Nikolas Klauser
9fdb4f3537 [libc++] Make bad_function_call::what() existence a matter of availability instead of ABI (#127697)
We're currently adding `bad_function_call::what()` behind an ABI flag,
even though adding it is not an ABI break and can be handled through
availability.
2025-04-25 10:45:46 +02:00