aboutsummaryrefslogtreecommitdiff
path: root/libcxx/include/string_view
AgeCommit message (Collapse)AuthorFilesLines
2023-12-18[libc++] Format the code base (#74334)Louis Dionne1-626/+509
This patch runs clang-format on all of libcxx/include and libcxx/src, in accordance with the RFC discussed at [1]. Follow-up patches will format the benchmarks, the test suite and remaining parts of the code. I'm splitting this one into its own patch so the diff is a bit easier to review. This patch was generated with: find libcxx/include libcxx/src -type f \ | grep -v 'module.modulemap.in' \ | grep -v 'CMakeLists.txt' \ | grep -v 'README.txt' \ | grep -v 'libcxx.imp' \ | grep -v '__config_site.in' \ | xargs clang-format -i A Git merge driver is available in libcxx/utils/clang-format-merge-driver.sh to help resolve merge and rebase issues across these formatting changes. [1]: https://discourse.llvm.org/t/rfc-clang-formatting-all-of-libc-once-and-for-all
2023-12-05[libc++] Replace uses of _VSTD:: by std:: (#74331)Louis Dionne1-7/+7
As part of the upcoming clang-formatting of libc++, this patch performs the long desired removal of the _VSTD macro. See https://discourse.llvm.org/t/rfc-clang-formatting-all-of-libc-once-and-for-all for the clang-format proposal.
2023-12-04[libc++][NFC] Add a few clang-format annotations (#74352)Louis Dionne1-1/+4
This is in preparation for clang-formatting the whole code base. These annotations are required either to avoid clang-format bugs or because the manually formatted code is significantly more readable than the clang-formatted alternative. All in all, it seems like very few annotations are required, which means that clang-format is doing a very good job in most cases.
2023-12-04[libc++] Rename _LIBCPP_INLINE_VISIBILITY to _LIBCPP_HIDE_FROM_ABI (#74095)Louis Dionne1-89/+89
In preparation for running clang-format on the whole code base, we are also removing mentions of the legacy _LIBCPP_INLINE_VISIBILITY macro in favor of the newer _LIBCPP_HIDE_FROM_ABI. We're still leaving the definition of _LIBCPP_INLINE_VISIBILITY to avoid creating needless breakage in case some older patches are checked-in with mentions of the old macro. After we branch for LLVM 18, we can do another pass to clean up remaining uses of the macro that might have gotten introduced by mistake (if any) and remove the macro itself at the same time. This is just a minor convenience to smooth out the transition as much as possible. See https://discourse.llvm.org/t/rfc-clang-formatting-all-of-libc-once-and-for-all for the clang-format proposal.
2023-11-07[libc++][hardening] Add `_LIBCPP_ASSERT_NON_NULL` to check for null pointers ↵Konstantin Varlamov1-27/+27
(#71428)
2023-09-18[libc++] [string_view] Remove operators made redundant by C++20 (#66206)Amirreza Ashouri1-37/+28
Thanks to Giuseppe D'Angelo for pointing this out on the cpplang Slack! The example implementation in https://eel.is/c++draft/string.view.comparison#example-1 was necessary when it was written, in C++17, but in C++20 we don't need that complexity anymore, because of the reversed candidates that are synthesized by the compiler.
2023-07-20[libc++][hardening] Categorize most assertions inside the container classes.varconst1-7/+8
This introduces: - `_LIBCPP_ASSERT_VALID_INPUT_RANGE`; - `_LIBCPP_ASSERT_VALID_CONTAINER_ACCESS`; - `_LIBCPP_ASSERT_VALID_ITERATOR_ACCESS`; - `_LIBCPP_ASSERT_VALID_ALLOCATOR`; - `_LIBCPP_ASSERT_INTERNAL`. Differential Revision: https://reviews.llvm.org/D155349
2023-07-14[libc++][NFC] Suppress -Wdeprecated-literal-operatorPo-yao Chang1-10/+10
Remove spaces between operator"" and identifier to suppress -Wdeprecated-literal-operator, and between operator and "" like how they are written in [string.view.literals] and [basic.string.literals]. Differential Revision: https://reviews.llvm.org/D155200
2023-06-28[libc++][hardening][NFC] Introduce `_LIBCPP_ASSERT_UNCATEGORIZED`.varconst1-27/+37
Replace most uses of `_LIBCPP_ASSERT` with `_LIBCPP_ASSERT_UNCATEGORIZED`. This is done as a prerequisite to introducing hardened mode to libc++. The idea is to make enabling assertions an opt-in with (somewhat) fine-grained controls over which categories of assertions are enabled. The vast majority of assertions are currently uncategorized; the new macro will allow turning on `_LIBCPP_ASSERT` (the underlying mechanism for all kinds of assertions) without enabling all the uncategorized assertions (in the future; this patch preserves the current behavior). Differential Revision: https://reviews.llvm.org/D153816
2023-06-27[libc++][hardening] Add an ABI macro `_LIBCPP_ABI_BOUNDED_ITERATORS`.varconst1-3/+3
Use the new macro instead of `_LIBCPP_DEBUG_ITERATOR_BOUNDS_CHECKING`. Differential Revision: https://reviews.llvm.org/D153895
2023-06-27[libc++] __iterator/readable_traits.h isn't standaloneIan Anderson1-1/+1
`__iterator/readable_traits.h` can't be used by itself, intantiating `iter_value_t` requires `__iterator/iterator_traits.h`. `readable_traits.h` can't include `iterator_traits.h` though because `iterator_traits.h` requires `readable_traits.h`. Move `iter_value_t` to `__iterator/iterator_traits.h` so that both headers can work standalone. Reviewed By: Mordante, #libc Differential Revision: https://reviews.llvm.org/D153828
2023-05-23[libc++] Updates C++2b to C++23.Mark de Wever1-4/+4
During the ISO C++ Committee meeting plenary session the C++23 Standard has been voted as technical complete. This updates the reference to c++2b to c++23 and updates the __cplusplus macro. Note since we use clang-tidy 16 a small work-around is needed. Clang knows -std=c++23 but clang-tidy not so for now force the lit compiler flag to use -std=c++2b instead of -std=c++23. Reviewed By: #libc, philnik, jloser, ldionne Differential Revision: https://reviews.llvm.org/D150795
2023-05-07[libc++][Modules] Add missing includes and exportsIan Anderson1-0/+1
Several headers are missing includes for things they use. type_traits.is_enum needs to export type_traits.integral_constant so that clients can access its `value` member without explicitly including __type_traits/integral_constant.h themselves. Make `subrange_fwd` a peer submodule to `subrange` rather than a submodule of it, and have `subrange` export `subrange_fwd`. That will make it easier to programmatically generate modules for the private detail headers, and it will accomplish the same effect that __ranges/subrange.h will make subrange_kind visible. Reviewed By: Mordante, #libc Differential Revision: https://reviews.llvm.org/D150055
2023-05-06[libc++][format] Fixes vector<bool> requirements.Mark de Wever1-1/+0
Makes sure the formatter for the vector<bool>::reference is enabled when only the header <vector> is included. Before this change it required <vector> and <format> to be included. This violated the requirements in the Standard. Fixes: https://llvm.org/PR61314 Reviewed By: #libc, ldionne Differential Revision: https://reviews.llvm.org/D149543
2023-04-09[libc++] Remove <cstdlib> includesNikolas Klauser1-0/+1
We changed the `abort` calls when trying to throw exceptions in `-fno-exceptions` mode to `__verbose_abort` calls, which removes the dependency in most files. Reviewed By: ldionne, #libc Spies: dim, emaste, mikhail.ramalho, smeenai, libcxx-commits Differential Revision: https://reviews.llvm.org/D146076
2023-03-19[libc++] Assert that lengths fit in difference_typeDavid Benjamin1-0/+1
This can help flag accidentally passing in negative values into the `string_view` constructor. This aligns with a similar check in `absl::string_view`. Fixes https://github.com/llvm/llvm-project/issues/61100 Reviewed By: #libc, Mordante Differential Revision: https://reviews.llvm.org/D145981
2023-03-12[libc++] Granularize <exception>Nikolas Klauser1-0/+1
This patch also updates the moved code to the new style (i.e. formatted, replaced marcos and typedefs) Reviewed By: ldionne, #libc Spies: arichardson, libcxx-commits Differential Revision: https://reviews.llvm.org/D145095
2023-03-08[libc++] Granularize <type_traits> includesNikolas Klauser1-1/+8
Reviewed By: ldionne, #libc, #libc_abi Spies: #libc_vendors, smeenai, libcxx-commits Differential Revision: https://reviews.llvm.org/D145320
2023-02-16[libc++] LWG 3857: allow `string_view` conversion when only traits varyJoe Loser1-4/+1
The `basic_string_view` constructor accepting a contiguous range rejects converting between `basic_string_view` even when only the trait types vary. This prevents conversions for converting from `basic_string_view<C, T1>` and `basic_string<C, T1, A>` to `basic_string_view<C, T2>`. Recently, this constructor was made `explicit`, so there's no reason to really forbid this conversion anymore. Relax the restriction that the trait types need to match in this constructor. Differential Revision: https://reviews.llvm.org/D143972
2023-02-15[libc++][NFC] Replace _LIBCPP_STD_VER > x with _LIBCPP_STD_VER >= xNikolas Klauser1-18/+18
This change is almost fully mechanical. The only interesting change is in `generate_feature_test_macro_components.py` to generate `_LIBCPP_STD_VER >=` instead. To avoid churn in the git-blame this commit should be added to the `.git-blame-ignore-revs` once committed. Reviewed By: ldionne, var-const, #libc Spies: jloser, libcxx-commits, arichardson, arphaman, wenlei Differential Revision: https://reviews.llvm.org/D143962
2023-01-31[libc++] Use bounded iterators in std::string_view when the debug mode is ↵Louis Dionne1-2/+19
enabled Differential Revision: https://reviews.llvm.org/D142903
2022-12-23[libc++] Add custom clang-tidy checksNikolas Klauser1-23/+23
Reviewed By: #libc, ldionne Spies: jwakely, beanz, smeenai, cfe-commits, tschuett, avogelsgesang, Mordante, sstefan1, libcxx-commits, ldionne, mgorny, arichardson, miyuki Differential Revision: https://reviews.llvm.org/D131963
2022-11-28[libc++][NFC] Remove stray whitespace in string_viewLouis Dionne1-15/+15
2022-11-28[libc++][NFC] Use using declaration instead of typedef in string_viewLouis Dionne1-12/+12
2022-11-05[libc++] Granularize <concept> includesNikolas Klauser1-0/+1
Reviewed By: ldionne, #libc Spies: libcxx-commits Differential Revision: https://reviews.llvm.org/D137283
2022-11-01[libc++] Move preferred_name declarations into the forward declaring headers ↵Nikolas Klauser1-9/+1
and add pmr preferred names We currently define the preferred names in multiple places. `basic_string` and `basic_string_view` also have a lot of aliases, which makes the declarations quite long. So let's only add the preferred names in forward-declaring headers to make the implementation more readable and have all the preferred names in one place. Reviewed By: ldionne Spies: EricWF, krytarowski, libcxx-commits Differential Revision: https://reviews.llvm.org/D135824
2022-10-03[libc++] Suppress -Wctad-maybe-unsupported on types w/o deduction guidesLouis Dionne1-0/+1
There are a handful of standard library types that are intended to support CTAD but don't need any explicit deduction guides to do so. This patch adds a dummy deduction guide to those types to suppress -Wctad-maybe-unsupported (which gets emitted in user code). This is a re-application of the original patch by Eric Fiselier in fcd549a7d828 which had been reverted due to reasons lost at this point. I also added the macro to a few more types. Reviving this patch was prompted by the discussion on https://llvm.org/D133425. Differential Revision: https://reviews.llvm.org/D133535
2022-09-03[NFC][libc++] Moves transitive includes location.Mark de Wever1-6/+6
As discussed in D132284 they will be moved to the end. Reviewed By: #libc, Mordante Differential Revision: https://reviews.llvm.org/D133212
2022-09-02[libc++] Make the naming of private member variables consistent and enforce ↵Nikolas Klauser1-27/+27
it through readability-identifier-naming Reviewed By: ldionne, #libc Spies: aheejin, sstefan1, libcxx-commits Differential Revision: https://reviews.llvm.org/D129386
2022-08-31[libc++] Reduces the number of transitive includes.Mark de Wever1-1/+1
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-26[libc++] Enable hash only for the correct typesNikolas Klauser1-2/+20
Also implement LWG3705. Fixes https://github.com/llvm/llvm-project/issues/55823 Reviewed By: ldionne, #libc Spies: libcxx-commits Differential Revision: https://reviews.llvm.org/D132338
2022-08-19[libc++][NFC] Rename the constexpr macrosNikolas Klauser1-56/+56
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-18[libc++] Make <ranges> non-experimentalLouis Dionne1-4/+4
When we ship LLVM 16, <ranges> won't be considered experimental anymore. We might as well do this sooner rather than later. Differential Revision: https://reviews.llvm.org/D132151
2022-08-13[libc++] Add a bunch of missing _LIBCPP_HIDE_FROM_ABINikolas Klauser1-1/+1
Reviewed By: ldionne, Mordante, var-const, huixie90, #libc Spies: jloser, libcxx-commits, arichardson, miyuki Differential Revision: https://reviews.llvm.org/D129968
2022-08-10[libc++] Fixes string_view comparison operators.Mark de Wever1-13/+13
While implementing `operator<=>` for `string_view` (D130295) @philnik pointed out `common_type` should be `type_identity`. Since it was an existing issue that wasn't addressed. This addresses the issue for both the new and existing equality and comparison operators. The test is based on the example posted in D130295. Reviewed By: philnik, #libc, huixie90 Differential Revision: https://reviews.llvm.org/D131322
2022-08-04[libc++] Uses operator<=> in string_viewMark de Wever1-5/+48
Implements: - LWG3432 Missing requirement for comparison_category Implements part of: - P1614R2 The Mothership has Landed Reviewed By: #libc, ldionne, jloser, philnik Differential Revision: https://reviews.llvm.org/D130295
2022-08-02[libc++] Implement P2499R0 (`string_view` range constructor should be ↵Igor Zhukov1-1/+1
`explicit`) Reviewed By: #libc, philnik, Mordante Spies: Mordante, jloser, philnik, libcxx-commits Differential Revision: https://reviews.llvm.org/D130785
2022-07-08[libc++] Make parameter names consistent and enforce the naming style using ↵Nikolas Klauser1-2/+2
readability-identifier-naming Ensure that parameter names have the style `__lower_case` Reviewed By: ldionne, #libc Spies: aheejin, sstefan1, libcxx-commits, miyuki Differential Revision: https://reviews.llvm.org/D129051
2022-06-27[libc++] Re-add transitive includes that had been removed since LLVM 14Louis Dionne1-0/+6
This commit re-adds transitive includes that had been removed by 4cd04d1687f1, c36870c8e79c, a83f4b9cda57, 1458458b558d, 2e2f3158c604, and 489637e66dd3. 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-22[libc++] Complete the implementation of N4190Nikolas Klauser1-2/+1
Fixes #37402 Reviewed By: ldionne Spies: EricWF, avogelsgesang, libcxx-commits, arphaman Differential Revision: https://reviews.llvm.org/D124346
2022-06-17[libc++] Mark standard-mandated includes as suchNikolas Klauser1-1/+12
Reviewed By: ldionne, Mordante, #libc, saugustine Spies: saugustine, MaskRay, arichardson, mstorsjo, jloser, libcxx-commits, arphaman Differential Revision: https://reviews.llvm.org/D127953
2022-06-15[libc++] Removes unneeded <iterator> includes.Mark de Wever1-1/+0
Reviewed By: #libc, philnik Differential Revision: https://reviews.llvm.org/D127675
2022-06-10[libc++] Granularize <iterator> includesNikolas Klauser1-1/+5
Reviewed By: ldionne, #libc Spies: libcxx-commits, wenlei Differential Revision: https://reviews.llvm.org/D127445
2022-06-09[libc++] Granularize __stringNikolas Klauser1-1/+2
Reviewed By: ldionne, #libc Spies: libcxx-commits, mgorny Differential Revision: https://reviews.llvm.org/D127156
2022-05-28[libc++] Remove unused __functional includesNikolas Klauser1-0/+1
Reviewed By: ldionne, #libc Spies: arichardson, smeenai, libcxx-commits, arphaman Differential Revision: https://reviews.llvm.org/D126098
2022-05-06[libc++][ranges] Implement `views::take`.Konstantin Varlamov1-13/+1
The view itself has been implemented previously -- this patch only adds the ability to pipe it. Also implements [P1739](https://wg21.link/p1739) (partially) and [LWG3407](https://wg21.link/lwg3407). Differential Revision: https://reviews.llvm.org/D123600
2022-03-30[libc++] Ensure that all public C++ headers include <__assert>Louis Dionne1-2/+3
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-13[libc++] Replace _LIBCPP_HAS_NO_CONCEPTS with _LIBCPP_STD_VER > 17. NFCI.Joe Loser1-10/+10
All supported compilers that support C++20 now support concepts. So, remove `_LIB_LIBCPP_HAS_NO_CONCEPTS` in favor of `_LIBCPP_STD_VER > 17`. Similarly in the tests, remove `// UNSUPPORTED: libcpp-no-concepts`. Differential Revision: https://reviews.llvm.org/D121528
2022-03-11[libc++] Remove raw call to debug handler from __char_traits_length_checkedLouis Dionne1-0/+9
As a fly-by fix, also move it closer to where it is needed, and add a comment explaining the existence of this weird function. Differential Revision: https://reviews.llvm.org/D121231
2022-02-16[libc++] Move everything related solely to _LIBCPP_ASSERT to its own fileLouis Dionne1-1/+1
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