-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[libc++] P1789R3: Library Support for Expansion Statements #167184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
032858a
7402319
350a3a1
fd296c5
e309910
a795b2c
2a238dc
49c6594
04a6f5f
b9781f4
94909a3
a7ed542
3e3ab8d
58b8e15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // REQUIRES: std-at-least-c++26 | ||
|
|
||
| // <utility> | ||
|
|
||
| // template<size_t I, class T, T... Values> | ||
| // [[nodiscard]] constexpr T get(integer_sequence<T, Values...>) noexcept; | ||
|
|
||
| // check that get is marked [[nodiscard]] | ||
|
|
||
| #include <utility> | ||
|
|
||
| void f() { | ||
| std::index_sequence<1> seq; | ||
| get<0>(seq); // expected-warning {{ignoring return value of function}} | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,53 @@ | ||||||||||||||||
| //===----------------------------------------------------------------------===// | ||||||||||||||||
| // | ||||||||||||||||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||||||||||||||
| // See https://llvm.org/LICENSE.txt for license information. | ||||||||||||||||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||||||||||||||
| // | ||||||||||||||||
| //===----------------------------------------------------------------------===// | ||||||||||||||||
|
|
||||||||||||||||
| // REQUIRES: std-at-least-c++26 | ||||||||||||||||
|
|
||||||||||||||||
| // <utility> | ||||||||||||||||
|
|
||||||||||||||||
| // template<size_t I, class T, T... Values> | ||||||||||||||||
| // struct tuple_element<I, integer_sequence<T, Values...>>; | ||||||||||||||||
| // template<size_t I, class T, T... Values> | ||||||||||||||||
| // struct tuple_element<I, const integer_sequence<T, Values...>>; | ||||||||||||||||
| // template<size_t I, class T, T... Values> | ||||||||||||||||
| // constexpr T get(integer_sequence<T, Values...>) noexcept; | ||||||||||||||||
|
Comment on lines
+13
to
+18
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think you should rename this file to "general.pass.cpp". |
||||||||||||||||
|
|
||||||||||||||||
| #include <cassert> | ||||||||||||||||
| #include <utility> | ||||||||||||||||
|
|
||||||||||||||||
| constexpr bool test_structured_bindings() { | ||||||||||||||||
| auto [elt0, elt1, elt2, elt3] = std::make_index_sequence<4>(); | ||||||||||||||||
|
|
||||||||||||||||
| assert(elt0 == 0); | ||||||||||||||||
| assert(elt1 == 1); | ||||||||||||||||
| assert(elt2 == 2); | ||||||||||||||||
| assert(elt3 == 3); | ||||||||||||||||
|
|
||||||||||||||||
| #if __cpp_structured_bindings >= 202411L | ||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We usually guard with a macro
Suggested change
I guess having a TEST_HAS_ macro declared in test_macros.h will be easier to spot and clean-up. |
||||||||||||||||
| []<typename...> { | ||||||||||||||||
| auto [... empty] = std::make_index_sequence<0>(); | ||||||||||||||||
| static_assert(sizeof...(empty) == 0); | ||||||||||||||||
|
|
||||||||||||||||
| auto [... size4] = std::make_index_sequence<4>(); | ||||||||||||||||
| static_assert(sizeof...(size4) == 4); | ||||||||||||||||
|
|
||||||||||||||||
| assert(size4...[0] == 0); | ||||||||||||||||
| assert(size4...[1] == 1); | ||||||||||||||||
| assert(size4...[2] == 2); | ||||||||||||||||
| assert(size4...[3] == 3); | ||||||||||||||||
| }(); | ||||||||||||||||
| #endif | ||||||||||||||||
|
|
||||||||||||||||
| return true; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| int main(int, char**) { | ||||||||||||||||
| test_structured_bindings(); | ||||||||||||||||
| static_assert(test_structured_bindings()); | ||||||||||||||||
| return 0; | ||||||||||||||||
| } | ||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // REQUIRES: std-at-least-c++26 | ||
|
|
||
| // <utility> | ||
|
|
||
| // template<class T, T... Values> | ||
| // struct tuple_size<integer_sequence<T, Values...>>; | ||
| // template<size_t I, class T, T... Values> | ||
| // struct tuple_element<I, integer_sequence<T, Values...>>; | ||
| // template<size_t I, class T, T... Values> | ||
| // struct tuple_element<I, const integer_sequence<T, Values...>>; | ||
| // template<size_t I, class T, T... Values> | ||
| // constexpr T get(integer_sequence<T, Values...>) noexcept; | ||
|
|
||
| #include <cassert> | ||
| #include <concepts> | ||
| #include <tuple> | ||
| #include <type_traits> | ||
| #include <utility> | ||
|
|
||
| void test() { | ||
| // std::tuple_size_v | ||
| using empty = std::integer_sequence<int>; | ||
| static_assert(std::tuple_size_v<empty> == 0); | ||
| static_assert(std::tuple_size_v<const empty> == 0); | ||
|
|
||
| using size4 = std::integer_sequence<int, 9, 8, 7, 2>; | ||
| static_assert(std::tuple_size_v<size4> == 4); | ||
| static_assert(std::tuple_size_v<const size4> == 4); | ||
|
|
||
| // std::tuple_element_t | ||
| static_assert(std::is_same_v<std::tuple_element_t<0, size4>, int>); | ||
| static_assert(std::is_same_v<std::tuple_element_t<1, size4>, int>); | ||
| static_assert(std::is_same_v<std::tuple_element_t<2, size4>, int>); | ||
| static_assert(std::is_same_v<std::tuple_element_t<3, size4>, int>); | ||
|
|
||
| static_assert(std::is_same_v<std::tuple_element_t<0, const size4>, int>); | ||
| static_assert(std::is_same_v<std::tuple_element_t<1, const size4>, int>); | ||
| static_assert(std::is_same_v<std::tuple_element_t<2, const size4>, int>); | ||
| static_assert(std::is_same_v<std::tuple_element_t<3, const size4>, int>); | ||
|
|
||
| // std::get | ||
| constexpr static size4 seq4; | ||
| constexpr std::same_as<int> decltype(auto) elt0 = get<0>(seq4); | ||
| static_assert(elt0 == 9); | ||
| static_assert(get<1>(seq4) == 8); | ||
| static_assert(get<2>(seq4) == 7); | ||
| static_assert(get<3>(seq4) == 2); | ||
|
|
||
| static_assert(noexcept(get<0>(seq4))); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // REQUIRES: std-at-least-c++26 | ||
|
|
||
| // <utility> | ||
|
|
||
| // template<size_t I, class T, T... Values> | ||
| // struct tuple_element<I, integer_sequence<T, Values...>>; | ||
| // template<size_t I, class T, T... Values> | ||
| // struct tuple_element<I, const integer_sequence<T, Values...>>; | ||
| // template<size_t I, class T, T... Values> | ||
| // constexpr T get(integer_sequence<T, Values...>) noexcept; | ||
|
|
||
| // Expect failures for tuple_element and get with empty integer_sequence | ||
|
|
||
| #include <utility> | ||
|
|
||
| void f() { | ||
| // expected-error-re@*:* {{static assertion failed{{.*}}Index out of bounds in std::tuple_element<> (std::integer_sequence)}} | ||
| using test1 = std::tuple_element_t<0, std::integer_sequence<int>>; | ||
| // expected-error-re@*:* {{static assertion failed{{.*}}Index out of bounds in std::tuple_element<> (const std::integer_sequence)}} | ||
| using test2 = std::tuple_element_t<0, const std::integer_sequence<int>>; | ||
|
|
||
| std::integer_sequence<int> empty; | ||
| // expected-error-re@*:* {{static assertion failed{{.*}}Index out of bounds in std::get<> (std::integer_sequence)}} | ||
| // expected-error-re@*:* {{invalid index 0 for pack {{.*}} of size 0}} | ||
| (void)std::get<0>(empty); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't a standard test, so it should go in
test/libcxx.