Skip to content
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

feat: add _computed-type-id_ for qualified type_of and decltype #1301

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions regression-tests/pure2-print.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ outer: @print type = {
(... && args);

y: (_: type_of(0)) = { }
y: (_: decltype(1LL)) = { }
y: (_: type_of(2 is int)::value_type) = { }
y: (_: decltype(new<long>(3))::element_type) = { }

}

Expand Down
10 changes: 10 additions & 0 deletions regression-tests/pure2-variadics-indexing.cpp2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
f0: <T...> () == :T...[0] = 32;
// f1: <T...> () == :T...[0]::value_type = 4; // Pending #533.
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);
}
2 changes: 1 addition & 1 deletion regression-tests/test-results/pure2-last-use.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ auto issue_313() -> void{
static_cast<void>(cpp2::impl::is(e, (e)));

auto f {cpp2_new<int>(0)};
static_cast<void>(cpp2::impl::is<decltype(f)>(f));// OK?
static_cast<void>(cpp2::impl::is<decltype(f)>(cpp2::move(f)));// OK?

auto g {cpp2_new<int>(0)};
for (
Expand Down
13 changes: 11 additions & 2 deletions regression-tests/test-results/pure2-print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,15 @@ CPP2_REQUIRES_ (cpp2::impl::cmp_greater_eq(sizeof...(Args),0u)) ;

#line 103 "pure2-print.cpp2"
public: static auto y([[maybe_unused]] cpp2::impl::in<CPP2_TYPEOF(0)> unnamed_param_1) -> void;
public: static auto y([[maybe_unused]] cpp2::impl::in<decltype(1LL)> unnamed_param_1) -> void;
public: static auto y([[maybe_unused]] cpp2::impl::in<CPP2_TYPEOF(cpp2::impl::is<int>(2))::value_type> unnamed_param_1) -> void;
public: static auto y([[maybe_unused]] cpp2::impl::in<decltype(cpp2_new<long>(3))::element_type> unnamed_param_1) -> void;
public: outer() = default;
public: outer(outer const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(outer const&) -> void = delete;


#line 105 "pure2-print.cpp2"
#line 108 "pure2-print.cpp2"
};

auto main() -> int;
Expand Down Expand Up @@ -204,8 +207,14 @@ requires (cpp2::impl::cmp_greater_eq(sizeof...(Args),0u)) {

#line 103 "pure2-print.cpp2"
auto outer::y([[maybe_unused]] cpp2::impl::in<CPP2_TYPEOF(0)> unnamed_param_1) -> void{}
#line 104 "pure2-print.cpp2"
auto outer::y([[maybe_unused]] cpp2::impl::in<decltype(1LL)> unnamed_param_1) -> void{}
#line 105 "pure2-print.cpp2"
auto outer::y([[maybe_unused]] cpp2::impl::in<CPP2_TYPEOF(cpp2::impl::is<int>(2))::value_type> unnamed_param_1) -> void{}
#line 106 "pure2-print.cpp2"
auto outer::y([[maybe_unused]] cpp2::impl::in<decltype(cpp2_new<long>(3))::element_type> unnamed_param_1) -> void{}

#line 107 "pure2-print.cpp2"
#line 110 "pure2-print.cpp2"
auto main() -> int{
outer::test();
}
Expand Down
12 changes: 12 additions & 0 deletions regression-tests/test-results/pure2-print.cpp2.output
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ outer:/* @print */ type =
y:(in _: type_of(0), ) =
{
}

y:(in _: decltype(1LL), ) =
{
}

y:(in _: type_of(2 is int)::value_type, ) =
{
}

y:(in _: decltype(new<long>(3))::element_type, ) =
{
}
}
ok (all Cpp2, passes safety checks)

38 changes: 38 additions & 0 deletions regression-tests/test-results/pure2-variadics-indexing.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

#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.
#line 3 "pure2-variadics-indexing.cpp2"
template<auto ...V> [[nodiscard]] constexpr auto f2() -> decltype(auto);
template<auto ...V> [[nodiscard]] constexpr auto f3() -> decltype(auto);
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 3 "pure2-variadics-indexing.cpp2"
template<auto ...V> [[nodiscard]] constexpr auto f2() -> decltype(auto) { return V...[0]; }
#line 4 "pure2-variadics-indexing.cpp2"
template<auto ...V> [[nodiscard]] constexpr auto f3() -> decltype(auto) { return CPP2_UFCS(front)(V...[0]); }
#line 5 "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)

Loading
Loading