Skip to content

Commit

Permalink
test: add test case for C++26 pack indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
JohelEGP committed Oct 7, 2024
1 parent 82c9a0a commit 0a5a449
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
11 changes: 11 additions & 0 deletions regression-tests/pure2-variadics-indexing.cpp2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
f0: <T...> () == :T...[0] = 32;
// f1: <T...> () == :T...[0]::value_type = 4; // Pending #533.
// 'V...[0]' needs to be made an _id-expression_.
// f2: <V...: _> () == V...[0];
// f3: <V...: _> () == V...[0].front();
main: () = {
static_assert(f0<i64>() == 32);
// static_assert(f1<std::integral_constant<i16, 8>>() == 4);
// static_assert(f2<2>() == 2);
// static_assert(f3<(:std::array = (1))>() == 1);
}
35 changes: 35 additions & 0 deletions regression-tests/test-results/pure2-variadics-indexing.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

#define CPP2_IMPORT_STD Yes

//=== Cpp2 type declarations ====================================================


#include "cpp2util.h"

#line 1 "pure2-variadics-indexing.cpp2"


//=== Cpp2 type definitions and function declarations ===========================

#line 1 "pure2-variadics-indexing.cpp2"
template<typename ...T> [[nodiscard]] constexpr auto f0() -> decltype(auto);
// f1: <T...> () == :T...[0]::value_type = 4; // Pending #533.
// 'V...[0]' needs to be made an _id-expression_.
// f2: <V...: _> () == V...[0];
// f3: <V...: _> () == V...[0].front();
#line 6 "pure2-variadics-indexing.cpp2"
auto main() -> int;

//=== Cpp2 function definitions =================================================

#line 1 "pure2-variadics-indexing.cpp2"
template<typename ...T> [[nodiscard]] constexpr auto f0() -> decltype(auto) { return T...[0]{32}; }

#line 6 "pure2-variadics-indexing.cpp2"
auto main() -> int{
static_assert(f0<cpp2::i64>() == 32);
// static_assert(f1<std::integral_constant<i16, 8>>() == 4);
// static_assert(f2<2>() == 2);
// static_assert(f3<(:std::array = (1))>() == 1);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pure2-variadics-indexing.cpp2... ok (all Cpp2, passes safety checks)

0 comments on commit 0a5a449

Please sign in to comment.