Skip to content

Commit

Permalink
test: add more test cases for deducible parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
JohelEGP committed Jul 10, 2023
1 parent 110aa2f commit ffacee7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
7 changes: 7 additions & 0 deletions regression-tests/pure2-bugfix-for-deducible-parameters.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@ main: () = {
_ = :<T> (x: std::vector<std::vector<T>>) = {}(:std::vector<std::vector<i32>> = ());
// Uncomment once `typename` is supported for template arguments.
// _ = :<T, U> (x: std::pair<T, typename U::value_type>, y: U) = {}(:std::pair = (0, 0), z);
_ = :<T, U> (x: std::array<T, U::value>, y: U) = {}(:std::array<i32, 0> = (), z);
init(out z, z);
id(z, z);

// Test that these are emitted unwrapped in case they are deducible.
(copy f := :<T> (x: std::vector<std::type_identity_t<T>>) = {})
static_assert(!std::is_invocable_v<decltype(f), std::vector<i32>>);
(copy f := :<T> (x: std::vector<std::vector<T>>) = {})
static_assert(std::is_invocable_v<decltype(f), std::vector<std::vector<i32>>>);
}

v: <T> type = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "cpp2util.h"


#line 25 "pure2-bugfix-for-deducible-parameters.cpp2"
#line 32 "pure2-bugfix-for-deducible-parameters.cpp2"
template<typename T> class v;


Expand All @@ -24,15 +24,15 @@ template<typename T> auto id(cpp2::in<std::integral_constant<cpp2::i32,T::value>
auto main() -> int;


#line 25 "pure2-bugfix-for-deducible-parameters.cpp2"
#line 32 "pure2-bugfix-for-deducible-parameters.cpp2"
template<typename T> class v {
public: explicit v(T const& x);
#line 26 "pure2-bugfix-for-deducible-parameters.cpp2"
#line 33 "pure2-bugfix-for-deducible-parameters.cpp2"
public: auto operator=(T const& x) -> v& ;

public: v(v const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(v const&) -> void = delete;
#line 27 "pure2-bugfix-for-deducible-parameters.cpp2"
#line 34 "pure2-bugfix-for-deducible-parameters.cpp2"
};


Expand All @@ -58,15 +58,31 @@ auto main() -> int{
(void) []<typename T>(std::vector<std::vector<T>> const& x) -> void{}(std::vector<std::vector<cpp2::i32>>{});
// Uncomment once `typename` is supported for template arguments.
// _ = :<T, U> (x: std::pair<T, typename U::value_type>, y: U) = {}(:std::pair = (0, 0), z);
(void) []<typename T, typename U>(std::array<T,U::value> const& x, U const& y) -> void{}(std::array<cpp2::i32,0>{}, z.value());
init(cpp2::out(&z.value()), z.value());
id(z.value(), std::move(z.value()));
{
auto f = []<typename T>(std::vector<std::type_identity_t<T>> const& x) -> void{};

// Test that these are emitted unwrapped in case they are deducible.

#line 27 "pure2-bugfix-for-deducible-parameters.cpp2"
static_assert(!(std::is_invocable_v<decltype(f),std::vector<cpp2::i32>>));
}
{
auto f = []<typename T>(std::vector<std::vector<T>> const& x) -> void{};

#line 29 "pure2-bugfix-for-deducible-parameters.cpp2"
static_assert(std::is_invocable_v<decltype(f),std::vector<std::vector<cpp2::i32>>>);
}
#line 30 "pure2-bugfix-for-deducible-parameters.cpp2"
}

#line 26 "pure2-bugfix-for-deducible-parameters.cpp2"
#line 33 "pure2-bugfix-for-deducible-parameters.cpp2"
template <typename T> v<T>::v(T const& x){}
#line 26 "pure2-bugfix-for-deducible-parameters.cpp2"
#line 33 "pure2-bugfix-for-deducible-parameters.cpp2"
template <typename T> auto v<T>::operator=(T const& x) -> v& {
return *this;
#line 26 "pure2-bugfix-for-deducible-parameters.cpp2"
#line 33 "pure2-bugfix-for-deducible-parameters.cpp2"
}

0 comments on commit ffacee7

Please sign in to comment.