Skip to content

Commit f6c399d

Browse files
committed
feat: accept type arguments in function calls
1 parent 8f13c29 commit f6c399d

8 files changed

+299
-77
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <cstddef>
2+
main: () = {
3+
_ = alignof(int);
4+
_ = sizeof(int);
5+
_ = typeid(int);
6+
_ = offsetof(t, a);
7+
_ = :<T> (_: T) _ = sizeof(T::value);(std::true_type());
8+
_ = :<T> (_: T) _ = sizeof(type T::value_type);(std::true_type());
9+
_ = alignof(const int);
10+
_ = sizeof(const int);
11+
_ = typeid(const int);
12+
_ = alignof(*int);
13+
_ = sizeof(*int);
14+
_ = typeid(*int);
15+
}
16+
#if defined(_MSC_VER) || defined(__GNUC__)
17+
_: int == __builtin_bit_cast(const int, 0);
18+
#endif
19+
t: @struct type = {
20+
a: int;
21+
}

regression-tests/pure2-print.cpp2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ outer: @print type = {
100100
all: <Args...: type> (args...: Args) -> bool =
101101
(... && args);
102102

103+
sizeof_dependent_type: <T> () = sizeof(type T::value_type);
104+
103105
}
104106

105107
main: () = {
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
3+
//=== Cpp2 type declarations ====================================================
4+
5+
6+
#include "cpp2util.h"
7+
8+
#line 1 "mixed-function-type-argument.cpp2"
9+
10+
#line 19 "mixed-function-type-argument.cpp2"
11+
class t;
12+
13+
14+
//=== Cpp2 type definitions and function declarations ===========================
15+
16+
#line 1 "mixed-function-type-argument.cpp2"
17+
#include <cstddef>
18+
auto main() -> int;
19+
#line 16 "mixed-function-type-argument.cpp2"
20+
#if defined(_MSC_VER) || defined(__GNUC__)
21+
int inline constexpr _{ __builtin_bit_cast(int const, 0) };
22+
#line 18 "mixed-function-type-argument.cpp2"
23+
#endif
24+
class t {
25+
public: int a;
26+
public: t(auto&& a_)
27+
CPP2_REQUIRES_ (std::is_convertible_v<CPP2_TYPEOF(a_), std::add_const_t<int>&>) ;
28+
29+
public: auto operator=(auto&& a_) -> t&
30+
CPP2_REQUIRES_ (std::is_convertible_v<CPP2_TYPEOF(a_), std::add_const_t<int>&>) ;
31+
32+
#line 21 "mixed-function-type-argument.cpp2"
33+
};
34+
35+
36+
//=== Cpp2 function definitions =================================================
37+
38+
#line 1 "mixed-function-type-argument.cpp2"
39+
40+
#line 2 "mixed-function-type-argument.cpp2"
41+
auto main() -> int{
42+
static_cast<void>(alignof(int));
43+
static_cast<void>(sizeof(int));
44+
static_cast<void>(typeid(int));
45+
static_cast<void>(offsetof(t, a));
46+
static_cast<void>([]<typename T>([[maybe_unused]] T const& unnamed_param_1) -> auto { return static_cast<void>(sizeof(T::value)); }(std::true_type()));
47+
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()));
48+
static_cast<void>(alignof(int const));
49+
static_cast<void>(sizeof(int const));
50+
static_cast<void>(typeid(int const));
51+
static_cast<void>(alignof(int*));
52+
static_cast<void>(sizeof(int*));
53+
static_cast<void>(typeid(int*));
54+
}
55+
56+
t::t(auto&& a_)
57+
requires (std::is_convertible_v<CPP2_TYPEOF(a_), std::add_const_t<int>&>)
58+
: a{ CPP2_FORWARD(a_) }{}
59+
60+
auto t::operator=(auto&& a_) -> t&
61+
requires (std::is_convertible_v<CPP2_TYPEOF(a_), std::add_const_t<int>&>) {
62+
a = CPP2_FORWARD(a_);
63+
return *this;}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mixed-function-type-argument.cpp2... ok (mixed Cpp1/Cpp2, Cpp2 code passes safety checks)
2+

regression-tests/test-results/pure2-print.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,15 @@ CPP2_REQUIRES_ (cpp2::impl::cmp_greater_eq(sizeof...(Args),0u)) ;
7070

7171
#line 100 "pure2-print.cpp2"
7272
public: template<typename ...Args> [[nodiscard]] static auto all(Args const& ...args) -> bool;
73+
74+
#line 103 "pure2-print.cpp2"
75+
public: template<typename T> static auto sizeof_dependent_type() -> void;
7376
public: outer() = default;
7477
public: outer(outer const&) = delete; /* No 'that' constructor, suppress copy */
7578
public: auto operator=(outer const&) -> void = delete;
7679

7780

78-
#line 103 "pure2-print.cpp2"
81+
#line 105 "pure2-print.cpp2"
7982
};
8083

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

202-
#line 105 "pure2-print.cpp2"
205+
#line 103 "pure2-print.cpp2"
206+
template<typename T> auto outer::sizeof_dependent_type() -> void { sizeof(typename T::value_type); }
207+
208+
#line 107 "pure2-print.cpp2"
203209
auto main() -> int{
204210
outer::test();
205211
}

regression-tests/test-results/pure2-print.cpp2.output

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ outer:/* @print */ type =
146146
}
147147

148148
all: <Args...: type, >(in args...: Args, ) -> move bool = (... && args);
149+
150+
sizeof_dependent_type: <T: type, >() = sizeof(type T::value_type);
149151
}
150152
ok (all Cpp2, passes safety checks)
151153

0 commit comments

Comments
 (0)