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: accept type arguments in function calls #923

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
21 changes: 21 additions & 0 deletions regression-tests/mixed-function-type-argument.cpp2
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <cstddef>
main: () = {
_ = alignof(int);
_ = sizeof(int);
_ = typeid(int);
_ = offsetof(t, a);
_ = :<T> (_: T) _ = sizeof(T::value);(std::true_type());
_ = :<T> (_: T) _ = sizeof(type T::value_type);(std::true_type());
JohelEGP marked this conversation as resolved.
Show resolved Hide resolved
_ = alignof(const int);
_ = sizeof(const int);
_ = typeid(const int);
_ = alignof(*int);
_ = sizeof(*int);
_ = typeid(*int);
}
#if defined(_MSC_VER) || defined(__GNUC__)
_: int == __builtin_bit_cast(const int, 0);
#endif
t: @struct type = {
a: int;
}
2 changes: 2 additions & 0 deletions regression-tests/pure2-print.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ outer: @print type = {
all: <Args...: type> (args...: Args) -> bool =
(... && args);

sizeof_dependent_type: <T> () = sizeof(type T::value_type);

}

main: () = {
Expand Down
63 changes: 63 additions & 0 deletions regression-tests/test-results/mixed-function-type-argument.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@


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


#include "cpp2util.h"

#line 1 "mixed-function-type-argument.cpp2"

#line 19 "mixed-function-type-argument.cpp2"
class t;


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

#line 1 "mixed-function-type-argument.cpp2"
#include <cstddef>
auto main() -> int;
#line 16 "mixed-function-type-argument.cpp2"
#if defined(_MSC_VER) || defined(__GNUC__)
int inline constexpr _{ __builtin_bit_cast(int const, 0) };
#line 18 "mixed-function-type-argument.cpp2"
#endif
class t {
public: int a;
public: t(auto&& a_)
CPP2_REQUIRES_ (std::is_convertible_v<CPP2_TYPEOF(a_), std::add_const_t<int>&>) ;

public: auto operator=(auto&& a_) -> t&
CPP2_REQUIRES_ (std::is_convertible_v<CPP2_TYPEOF(a_), std::add_const_t<int>&>) ;

#line 21 "mixed-function-type-argument.cpp2"
};


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

#line 1 "mixed-function-type-argument.cpp2"

#line 2 "mixed-function-type-argument.cpp2"
auto main() -> int{
static_cast<void>(alignof(int));
static_cast<void>(sizeof(int));
static_cast<void>(typeid(int));
static_cast<void>(offsetof(t, a));
static_cast<void>([]<typename T>([[maybe_unused]] T const& unnamed_param_1) -> auto { return static_cast<void>(sizeof(T::value)); }(std::true_type()));
static_cast<void>([]<typename T>([[maybe_unused]] T const& unnamed_param_1) -> auto { return static_cast<void>(sizeof(typename T::value_type)); }(std::true_type()));
static_cast<void>(alignof(int const));
static_cast<void>(sizeof(int const));
static_cast<void>(typeid(int const));
static_cast<void>(alignof(int*));
static_cast<void>(sizeof(int*));
static_cast<void>(typeid(int*));
}

t::t(auto&& a_)
requires (std::is_convertible_v<CPP2_TYPEOF(a_), std::add_const_t<int>&>)
: a{ CPP2_FORWARD(a_) }{}

auto t::operator=(auto&& a_) -> t&
requires (std::is_convertible_v<CPP2_TYPEOF(a_), std::add_const_t<int>&>) {
a = CPP2_FORWARD(a_);
return *this;}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mixed-function-type-argument.cpp2... ok (mixed Cpp1/Cpp2, Cpp2 code passes safety checks)

10 changes: 8 additions & 2 deletions regression-tests/test-results/pure2-print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,15 @@ CPP2_REQUIRES_ (cpp2::impl::cmp_greater_eq(sizeof...(Args),0u)) ;

#line 100 "pure2-print.cpp2"
public: template<typename ...Args> [[nodiscard]] static auto all(Args const& ...args) -> bool;

#line 103 "pure2-print.cpp2"
public: template<typename T> static auto sizeof_dependent_type() -> void;
public: outer() = default;
public: outer(outer const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(outer const&) -> void = delete;


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

auto main() -> int;
Expand Down Expand Up @@ -199,7 +202,10 @@ requires (cpp2::impl::cmp_greater_eq(sizeof...(Args),0u)) {
template<typename ...Args> [[nodiscard]] auto outer::all(Args const& ...args) -> bool {
return (... && args); }

#line 105 "pure2-print.cpp2"
#line 103 "pure2-print.cpp2"
template<typename T> auto outer::sizeof_dependent_type() -> void { sizeof(typename T::value_type); }

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

all: <Args...: type, >(in args...: Args, ) -> move bool = (... && args);

sizeof_dependent_type: <T: type, >() = sizeof(type T::value_type);
}
ok (all Cpp2, passes safety checks)

Loading
Loading