Commit Graph

74 Commits

Author SHA1 Message Date
Mark de Wever
8ff2d6af69 [libc++] Reduces the number of transitive includes.
This defines a new policy for removal of transitive includes.
The goal of the policy it to make it relatively easy to remove
headers when needed, but avoid breaking developers using and
vendors shipping libc++.

The method used is to guard transitive includes based on the
C++ language version. For the upcoming C++23 we can remove
headers when we want, but for other language versions we try
to keep it to a minimum.

In this code the transitive include of `<chrono>` is removed
since D128577 introduces a header cycle between `<format>`
and `<chrono>`. This cycle is indirectly required by the
Standard. Our cycle dependency tool basically is a grep based
tool, so it needs some hints to ignore cycles. With the input
of our transitive include tests we can create a better tool.
However that's out of the scope of this patch.

Note the flag `_LIBCPP_REMOVE_TRANSITIVE_INCLUDES` remains
unchanged. So users can still opt-out of transitives includes
entirely.

Reviewed By: #libc, ldionne, philnik

Differential Revision: https://reviews.llvm.org/D132284
2022-08-31 19:50:03 +02:00
Nikolas Klauser
5146b57b40 [libc++][NFC] Rename the constexpr macros
This was discussed on Discord with the consensus that we should rename the macros.

Reviewed By: ldionne, Mordante, var-const, avogelsgesang, jloser, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D131498
2022-08-19 15:35:02 +02:00
Nikolas Klauser
4887d047a3 [libc++][NFC] Replace enable_if with __enable_if_t in a few places
Reviewed By: ldionne, #libc

Spies: jloser, libcxx-commits

Differential Revision: https://reviews.llvm.org/D128400
2022-07-04 11:09:34 +02:00
Louis Dionne
de4a57cb21 [libc++] Re-add transitive includes that had been removed since LLVM 14
This commit re-adds transitive includes that had been removed by
4cd04d1687, c36870c8e7, a83f4b9cda, 1458458b55, 2e2f3158c6,
and 489637e66d. This should cover almost all the includes that had
been removed since LLVM 14 and that would contribute to breaking user
code when releasing LLVM 15.

It is possible to disable the inclusion of these headers by defining
_LIBCPP_REMOVE_TRANSITIVE_INCLUDES. The intent is that vendors will
enable that macro and start fixing downstream issues immediately. We
can then remove the macro (and the transitive includes) by default in
a future release. That way, we will break users only once by removing
transitive includes in bulk instead of doing it bit by bit a every
release, which is more disruptive for users.

Note 1: The set of headers to re-add was found by re-generating the
        transitive include test on a checkout of release/14.x, which
        provided the list of all transitive includes we used to provide.

Note 2: Several includes of <vector>, <optional>, <array> and <unordered_map>
        have been added in this commit. These transitive inclusions were
        added when we implemented boyer_moore_searcher in <functional>.

Note 3: This is a best effort patch to try and resolve downstream breakage
        caused since branching LLVM 14. I wasn't able to perfectly mirror
        transitive includes in LLVM 14 for a few headers, so I added a
        release note explaining it. To summarize, adding boyer_moore_searcher
        created a bunch of circular dependencies, so we have to break
        backwards compatibility in a few cases.

Differential Revision: https://reviews.llvm.org/D128661
2022-06-27 22:18:19 -04:00
Nikolas Klauser
db1978b674 [libc++] Mark standard-mandated includes as such
Reviewed By: ldionne, Mordante, #libc, saugustine

Spies: saugustine, MaskRay, arichardson, mstorsjo, jloser, libcxx-commits, arphaman

Differential Revision: https://reviews.llvm.org/D127953
2022-06-17 20:43:33 +02:00
Mark de Wever
4cd04d1687 [libc++] Removes unneeded <iterator> includes.
Reviewed By: #libc, philnik

Differential Revision: https://reviews.llvm.org/D127675
2022-06-15 18:14:05 +02:00
Nikolas Klauser
3cd4531b9b [libc++] Granularize <iterator> includes
Reviewed By: ldionne, #libc

Spies: libcxx-commits, wenlei

Differential Revision: https://reviews.llvm.org/D127445
2022-06-10 22:43:57 +02:00
Louis Dionne
385cc25a53 [libc++] Ensure that all public C++ headers include <__assert>
This patch changes the requirement for getting the declaration of the
assertion handler from including <__assert> to including any public
C++ header of the library. Note that C compatibility headers are
excluded because we don't implement all the C headers ourselves --
some of them are taken straight from the C library, like assert.h.

It also adds a generated test to check it. Furthermore, this new
generated test is designed in a way that will make it possible to
replace almost all the existing test-generation scripts with this
system in upcoming patches.

Differential Revision: https://reviews.llvm.org/D122506
2022-03-30 15:05:31 -04:00
Nikolas Klauser
1458458b55 [libc++] Remove <utility> includes
Reviewed By: ldionne, Quuxplusone, #libc

Spies: libcxx-commits, arphaman

Differential Revision: https://reviews.llvm.org/D121054
2022-03-17 00:12:33 +01:00
Nikolas Klauser
52915d78f4 [libc++] Granularize <utility> includes
Reviewed By: ldionne, #libc

Spies: EricWF, libcxx-commits, arphaman

Differential Revision: https://reviews.llvm.org/D120466
2022-03-05 19:31:46 +01:00
Louis Dionne
f87aa19be6 [libc++] Move everything related solely to _LIBCPP_ASSERT to its own file
This is the first step towards disentangling the debug mode and assertions
in libc++. This patch doesn't make any functional change: it simply moves
_LIBCPP_ASSERT-related stuff to its own file so as to make it clear that
libc++ assertions and the debug mode are different things. Future patches
will make it possible to enable assertions without enabling the debug
mode.

Differential Revision: https://reviews.llvm.org/D119769
2022-02-16 12:49:50 -05:00
Nikolas Klauser
2e2f3158c6 [libc++] Granularize algorithm includes
Reviewed By: Mordante, ldionne, Quuxplusone, #libc, #libc_abi

Spies: #libc_vendors, libcxx-commits, miyuki

Differential Revision: https://reviews.llvm.org/D119667
2022-02-16 04:12:22 +01:00
Nikolas Klauser
2a8f9a5e95 [libc++] Implement P0627R6 (Function to mark unreachable code)
Reviewed By: ldionne, Quuxplusone, #libc

Spies: arichardson, mstorsjo, libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D119152
2022-02-14 20:52:51 +01:00
Arthur O'Dwyer
fa6b9e4010 [libc++] Normalize all our '#pragma GCC system_header', and regression-test.
Now we'll notice if a header forgets to include this magic phrase.

Differential Revision: https://reviews.llvm.org/D118800
2022-02-04 12:27:19 -05:00
Louis Dionne
eb8650a757 [runtimes][NFC] Remove filenames at the top of the license notice
We've stopped doing it in libc++ for a while now because these names
would end up rotting as we move things around and copy/paste stuff.
This cleans up all the existing files so as to stop the spreading
as people copy-paste headers around.
2021-11-17 16:30:52 -05:00
Louis Dionne
4e0ea2cf2e [libc++] Use enable_if_t instead of _EnableIf
I just ran into a compiler error involving __bind_back and some overloads
that were being disabled with _EnableIf. I noticed that the error message
was quite bad and did not mention the reason for the overload being
excluded. Specifically, the error looked like this:

     candidate template ignored: substitution failure [with _Args =
     <ContiguousView>]: no member named '_EnableIfImpl' in 'std::_MetaBase<false>'

Instead, when using enable_if or enable_if_t, the compiler is clever and
can produce better diagnostics, like so:

     candidate template ignored: requirement 'is_invocable_v<
          std::__bind_back_op<1, std::integer_sequence<unsigned long, 0>>,
          std::ranges::views::__transform::__fn &, std::tuple<PlusOne> &,
          ContiguousView>' was not satisfied [with _Args = <ContiguousView>]

Basically, it tries to do a poor man's implementation of concepts, which
is already a lot better than simply complaining about substitution failure.

Hence, this commit uses enable_if_t instead of _EnableIf whenever
possible. That is both more straightforward than using the internal
helper, and also leads to better error messages in those cases.

I understand the motivation for _EnableIf's implementation was to improve
compile-time performance, however I believe striving to improve error
messages is even more important for our QOI, hence this patch. Furthermore,
it is unclear that _EnableIf actually improved compile-time performance
in any noticeable way (see discussion in the review for details).

Differential Revision: https://reviews.llvm.org/D108216
2021-09-08 09:09:28 -04:00
Louis Dionne
0166690401 [libc++] Remove workarounds for the lack of deduction guides in C++17
All supported compilers have supported deduction guides in C++17 for a
while, so this isn't necessary anymore.

Differential Revision: https://reviews.llvm.org/D108213
2021-08-18 08:57:25 -04:00
Arthur O'Dwyer
bfbd73f87d [libc++] Alphabetize and include-what-you-use. NFCI.
Differential Revision: https://reviews.llvm.org/D102781
2021-05-29 19:54:48 -04:00
Louis Dionne
4cd6ca102a [libc++] NFC: Normalize #endif // comment indentation 2021-04-20 12:03:32 -04:00
Arthur O'Dwyer
781c476ce0 [libc++] ADL-proof vector<bool> by adding _VSTD:: qualification on calls.
This affects only vectors with weird/malicious allocators,
the same corner case covered in D91708, but for `vector<bool>` this time.

Also ADL-proof <__tree>, which affects only sets and maps with weird/malicious
allocators where the ADL trap is in the *fancy pointer type*.

Also drive-by _VSTD:: qualification in the guts of std::bind,
std::packaged_task, std::condition_variable.

Differential Revision: https://reviews.llvm.org/D93424
2021-01-06 18:23:50 -05:00
Arthur O'Dwyer
d586f92c94 [libc++] Consistently replace std:: qualification with _VSTD:: or nothing. NFCI.
I used a lot of `git grep` to find places where `std::` was being used
outside of comments and assert-messages. There were three outcomes:

- Qualified function calls, e.g. `std::move` becomes `_VSTD::move`.
    This is the most common case.

- Typenames that don't need qualification, e.g. `std::allocator` becomes `allocator`.
    Leaving these as `_VSTD::allocator` would also be fine, but I decided
    that removing the qualification is more consistent with existing practice.

- Names that specifically need un-versioned `std::` qualification,
    or that I wasn't sure about. For example, I didn't touch any code in
    <atomic>, <math.h>, <new>, or any ext/ or experimental/ headers;
    and I didn't touch any instances of `std::type_info`.

In some deduction guides, we were accidentally using `class Alloc = typename std::allocator<T>`,
despite `std::allocator<T>`'s type-ness not being template-dependent.
Because `std::allocator` is a qualified name, this did parse as we intended;
but what we meant was simply `class Alloc = allocator<T>`.

Differential Revision: https://reviews.llvm.org/D92250
2020-12-01 22:13:39 -05:00
Louis Dionne
12805513a6 [libc++] Remove some workarounds for C++03
We don't support any compiler that doesn't support variadics and rvalue
references in C++03 mode, so these workarounds can be dropped. There's
still *a lot* of cruft related to these workarounds, but I try to tackle
a bit of it here and there.
2020-10-09 12:35:13 -04:00
Louis Dionne
23776a178f [libc++] Add assertions on OOB accesses in std::array when the debug mode is enabled
Like we do for empty std::array, make sure we have assertions in place
for obvious out-of-bounds issues in std::array when the debug mode is
enabled (which isn't by default).
2020-06-01 16:37:39 -04:00
Louis Dionne
66a14d151e [libc++] NFC: Minor refactoring in std::array 2020-06-01 16:28:44 -04:00
Louis Dionne
7265ff928a [libc++] Fix issues with the triviality of std::array
The Standard is currently unimplementable. We have to pick between:

1. Not implementing constexpr support properly in std::array<T, 0>
2. Making std::array<T, 0> non-trivial even when T is trivial
3. Returning nullptr from std::array<T, 0>::begin()

Libc++ initially picked (1). In 77b9abfc8e, we started implementing constexpr properly, but lost the guarantee of triviality. Since it seems like both (1) and (2) are really important, it seems like (3) is the only viable option for libc++, after all. This is also what other implementations are doing.

This patch moves libc++ from (1) to (3).

It also:
- Improves the test coverage for the various ways of initializing std::array
- Adds tests for the triviality of std::array
- Adds tests for the aggregate-ness of std::array

Reviewed By: #libc, miscco, EricWF, zoecarver

Differential Revision: https://reviews.llvm.org/D80821
2020-05-29 16:32:55 -07:00
Louis Dionne
77b9abfc8e [libc++] Complete overhaul of constexpr support in std::array
This commit adds missing support for constexpr in std::array under all
standard modes up to and including C++20. It also transforms the <array>
tests to check for constexpr-friendliness under the right standard modes.

Fixes https://llvm.org/PR40124
Fixes rdar://57522096
Supersedes https://reviews.llvm.org/D60666

Differential Revision: https://reviews.llvm.org/D80452
2020-05-28 12:31:06 -04:00
Louis Dionne
0161874c04 [libc++] NFC: Inline array<T,N>::at methods inside the class
All other methods are defined in the class, so this increases consistency.
2020-05-22 09:24:07 -04:00
Eric Fiselier
c6eb584c64 [libc++] Fix recursive instantiation in std::array.
The use of the `&& ...` fold expression in std::array's deduction guides
recursively builds a set of binary operator expressions of depth N where
`N` is the number of elements in the initializer.

This is problematic because arrays may be large, and instantiation
depth is limited.

This patch addresses the issue by flattening the SFINAE using
the existing `__all` type trait.
2020-04-09 17:42:10 -04:00
Marek Kurdej
e93e58c6c4 Reland [libc++] [P0325] Implement to_array from LFTS with updates.
Fixed expected errors and notes.

Summary:
This patch implements https://wg21.link/P0325.

Reviewers: EricWF, mclow.lists, ldionne, lichray

Reviewed By: ldionne, lichray

Subscribers: lichray, dexonsmith, zoecarver, christof, ldionne, libcxx-commits

Tags: #libc

Differential Revision: https://reviews.llvm.org/D69882
2020-01-31 11:47:18 +01:00
Marek Kurdej
5e7017273f Revert "[libc++] [P0325] Implement to_array from LFTS with updates."
This reverts commit 86aae78268.

A test is failing on "Release" build without assertions enabled (Fedora 31 on x86_64).
2020-01-31 09:45:50 +01:00
Marek Kurdej
86aae78268 [libc++] [P0325] Implement to_array from LFTS with updates.
Summary:
This patch implements https://wg21.link/P0325.
Please mind that at it is my first contribution to libc++, so I may have forgotten to abide to some conventions.

Reviewers: EricWF, mclow.lists, ldionne, lichray

Reviewed By: ldionne, lichray

Subscribers: lichray, dexonsmith, zoecarver, christof, ldionne, libcxx-commits

Tags: #libc

Differential Revision: https://reviews.llvm.org/D69882
2020-01-30 13:38:37 +01:00
Louis Dionne
2b0c7abba3 [libc++] Declare std::tuple_element as struct instead of class
Similarly to https://reviews.llvm.org/rL350972, this revision changes
std::tuple_element from class to struct.

Fixes PR41331.
Thanks to Jan Wilken Dörrie for the patch.

Differential Revision: https://reviews.llvm.org/D60069

llvm-svn: 357411
2019-04-01 16:39:34 +00:00
Marshall Clow
9ea0e473f0 Mark 'front()' and 'back()' as noexcept for array/deque/string/string_view. These are just rebranded 'operator[]', and should be noexcept like it is.
llvm-svn: 356435
2019-03-19 03:30:07 +00:00
Marshall Clow
5f6a5ac19c Add noexcept to operator[] for array and deque. This is an extension. We already do this for string and string_view. This should give better codegen inside of noexcept functions.
llvm-svn: 356209
2019-03-14 21:56:57 +00:00
Chandler Carruth
57b08b0944 Update more file headers across all of the LLVM projects in the monorepo
to reflect the new license. These used slightly different spellings that
defeated my regular expressions.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

llvm-svn: 351648
2019-01-19 10:56:40 +00:00
Marshall Clow
e495760140 Change from a to a . Fixes PR#39871.
llvm-svn: 350972
2019-01-11 21:57:12 +00:00
Marshall Clow
f56972e224 Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955
llvm-svn: 342073
2018-09-12 19:41:40 +00:00
Marshall Clow
07d8ac0ab5 Implement P1023: constexpr comparison operators for std::array
llvm-svn: 338668
2018-08-02 02:11:06 +00:00
Marshall Clow
0ca8c0895c Implement deduction guides for <array>; Reviewed as https://reviews.llvm.org/D46964
llvm-svn: 332768
2018-05-18 21:01:04 +00:00
Eric Fiselier
1a78ae3c89 Fix size and alignment of array<T, 0>.
An array T[1] isn't necessarily the same say when it's
a member of a struct. This patch addresses that problem and corrects
the tests to deal with it.

llvm-svn: 324545
2018-02-07 23:50:25 +00:00
Eric Fiselier
59cdf90ac8 [libc++] Fix PR35491 - std::array of zero-size doesn't work with non-default constructible types.
Summary:
This patch fixes llvm.org/PR35491 and LWG2157  (https://cplusplus.github.io/LWG/issue2157)

The fix attempts to maintain ABI compatibility by replacing the array with a instance of `aligned_storage`.

Reviewers: mclow.lists, EricWF

Reviewed By: EricWF

Subscribers: lichray, cfe-commits

Differential Revision: https://reviews.llvm.org/D41223

llvm-svn: 324526
2018-02-07 21:06:13 +00:00
Nirav Dave
936ff58476 Revert "[libc++] Fix PR35491 - std::array of zero-size doesn't work with non-default constructible types."
Revert "Fix initialization of array<const T, 0> with GCC."
Revert "Make array<const T, 0> non-CopyAssignable and make swap and fill ill-formed."

This reverts commit r324182, r324185, and r324194 which were causing issues with zero-length std::arrays.

llvm-svn: 324309
2018-02-06 03:03:37 +00:00
Eric Fiselier
c6b3c7bb63 Fix initialization of array<const T, 0> with GCC.
Previously, when handling zero-sized array of const objects we
used a const version of aligned_storage_t, which is not an array type.
However, GCC complains about initialization of the form: array<const T, 0> arr = {};

This patch fixes that bug by making the dummy object used to represent
the zero-sized array an array itself. This avoids GCC's complaints
about the uninitialized const member.

llvm-svn: 324194
2018-02-04 08:02:35 +00:00
Eric Fiselier
192622dc49 Make array<const T, 0> non-CopyAssignable and make swap and fill ill-formed.
The standard isn't exactly clear how std::array should handle zero-sized arrays
with const element types. In particular W.R.T. copy assignment, swap, and fill.

This patch takes the position that those operations should be ill-formed,
and makes changes to libc++ to make it so.

This follows up on commit r324182.

llvm-svn: 324185
2018-02-04 02:17:02 +00:00
Eric Fiselier
afeda5c251 [libc++] Fix PR35491 - std::array of zero-size doesn't work with non-default constructible types.
Summary:
This patch fixes llvm.org/PR35491 and LWG2157  (https://cplusplus.github.io/LWG/issue2157)

The fix attempts to maintain ABI compatibility by replacing the array with a instance of `aligned_storage`.

Reviewers: mclow.lists, EricWF

Reviewed By: EricWF

Subscribers: lichray, cfe-commits

Differential Revision: https://reviews.llvm.org/D41223

llvm-svn: 324182
2018-02-04 01:03:08 +00:00
Marshall Clow
72c8fad427 First part of P0600 - '[[nodiscard] in the standard library'. Mark the 'empty()' methods of all the containers as nodiscard. If you're calling empty() w/o looking at the result, you probably meanto to call 'clear()'. c++2a only
llvm-svn: 318269
2017-11-15 05:51:26 +00:00
Marshall Clow
6db379a2c8 [array.tuple]/1 says that instantiating tuple_element<N, array<T, M>> is ill-formed if N >= M. We didn't do that. Add a static_assert to cause a failure, and a test that checks that we failed
llvm-svn: 305191
2017-06-12 14:41:37 +00:00
Eric Fiselier
a016efb1dc [Libc++] Use #pragma push_macro/pop_macro to better handle min/max on Windows
Summary:
This patch improves how libc++ handles min/max macros within the headers. Previously libc++ would undef them and emit a warning.
This patch changes libc++ to use `#pragma push_macro`  to save the macro before undefining it, and `#pragma pop_macro` to restore the macros and the end of the header.

Reviewers: mclow.lists, bcraig, compnerd, EricWF

Reviewed By: EricWF

Subscribers: cfe-commits, krytarowski

Differential Revision: https://reviews.llvm.org/D33080

llvm-svn: 304357
2017-05-31 22:07:49 +00:00
Eric Fiselier
208156e88b Replace _LIBCPP_HAS_NO_<C++03 feature> with _LIBCPP_CXX03_LANG in <array>
llvm-svn: 300412
2017-04-16 02:50:40 +00:00
Marshall Clow
e78269506f Implement the missing constexpr stuff in <array>. Fixes PR#31645.
llvm-svn: 292091
2017-01-16 03:02:10 +00:00