|
| 1 | + |
| 2 | +#define CPP2_IMPORT_STD Yes |
| 3 | + |
| 4 | +//=== Cpp2 type declarations ==================================================== |
| 5 | + |
| 6 | + |
| 7 | +#include "cpp2util.h" |
| 8 | + |
| 9 | +#line 1 "pure2-bugfix-for-deducible-parameters.cpp2" |
| 10 | + |
| 11 | +#line 31 "pure2-bugfix-for-deducible-parameters.cpp2" |
| 12 | +template<typename T> class v; |
| 13 | + |
| 14 | + |
| 15 | +//=== Cpp2 type definitions and function declarations =========================== |
| 16 | + |
| 17 | +#line 1 "pure2-bugfix-for-deducible-parameters.cpp2" |
| 18 | +// Dependent, non-deducible parameters |
| 19 | +// are wrapped like non-dependent parameters. |
| 20 | +#line 3 "pure2-bugfix-for-deducible-parameters.cpp2" |
| 21 | +template<typename T> auto init(cpp2::out<std::integral_constant<cpp2::i32,T::value>> x) -> void; |
| 22 | +template<typename T> auto init(cpp2::out<std::integral_constant<cpp2::i32,T::value>> x, [[maybe_unused]] T const& unnamed_param_2) -> void; |
| 23 | +template<typename T> [[nodiscard]] auto id(cpp2::in<std::integral_constant<cpp2::i32,T::value>> x) -> auto&&; |
| 24 | +template<typename T> auto id(cpp2::in<std::integral_constant<cpp2::i32,T::value>> x, T const& y) -> void; |
| 25 | + |
| 26 | +auto main() -> int; |
| 27 | + |
| 28 | +#line 31 "pure2-bugfix-for-deducible-parameters.cpp2" |
| 29 | +template<typename T> class v { |
| 30 | + public: explicit v(T const& x); |
| 31 | +#line 32 "pure2-bugfix-for-deducible-parameters.cpp2" |
| 32 | + public: auto operator=(T const& x) -> v& ; |
| 33 | + public: v(v const&) = delete; /* No 'that' constructor, suppress copy */ |
| 34 | + public: auto operator=(v const&) -> void = delete; |
| 35 | + |
| 36 | +#line 33 "pure2-bugfix-for-deducible-parameters.cpp2" |
| 37 | +}; |
| 38 | + |
| 39 | + |
| 40 | +//=== Cpp2 function definitions ================================================= |
| 41 | + |
| 42 | +#line 1 "pure2-bugfix-for-deducible-parameters.cpp2" |
| 43 | + |
| 44 | +#line 3 "pure2-bugfix-for-deducible-parameters.cpp2" |
| 45 | +template<typename T> auto init(cpp2::out<std::integral_constant<cpp2::i32,T::value>> x) -> void{x.construct(); } |
| 46 | +template<typename T> auto init(cpp2::out<std::integral_constant<cpp2::i32,T::value>> x, [[maybe_unused]] T const& unnamed_param_2) -> void{x.construct(); } |
| 47 | +template<typename T> [[nodiscard]] auto id(cpp2::in<std::integral_constant<cpp2::i32,T::value>> x) -> auto&& { return x; } |
| 48 | +template<typename T> auto id(cpp2::in<std::integral_constant<cpp2::i32,T::value>> x, T const& y) -> void{cpp2::Default.expects(&x == &y, ""); } |
| 49 | + |
| 50 | +auto main() -> int{ |
| 51 | + using zero = std::integral_constant<cpp2::i32,0>; |
| 52 | + |
| 53 | + cpp2::deferred_init<zero> z; |
| 54 | + init<zero>(cpp2::out(&z)); |
| 55 | + cpp2::Default.expects(&id<zero>(z.value()) == &z.value(), ""); |
| 56 | + |
| 57 | + // Deducible parameters. |
| 58 | + static_cast<void>(v{0}); |
| 59 | + static_cast<void>([]<typename T>(std::vector<T> const& x) mutable -> void{}(std::vector<cpp2::i32>{})); |
| 60 | + static_cast<void>([]<typename T>(std::vector<std::vector<T>> const& x) mutable -> void{}(std::vector<std::vector<cpp2::i32>>{})); |
| 61 | + // _ = :<T, U> (x: std::pair<T, typename U::value_type>, y: U) = {}(:std::pair = (0, 0), z); // Blocked on #727. |
| 62 | + static_cast<void>([]<typename T, typename U>(std::array<T,U::value> const& x, U const& y) mutable -> void{}(std::array<cpp2::i32,0>{}, z.value())); |
| 63 | + init(cpp2::out(&z.value()), z.value()); |
| 64 | + id(z.value(), std::move(z.value())); |
| 65 | +{ |
| 66 | +auto f = []<typename T>(std::vector<std::type_identity_t<T>> const& x) mutable -> void{}; |
| 67 | + |
| 68 | + // Test that these are emitted unwrapped in case they are deducible. |
| 69 | + |
| 70 | +#line 26 "pure2-bugfix-for-deducible-parameters.cpp2" |
| 71 | + static_assert(!(std::is_invocable_v<decltype(f),std::vector<cpp2::i32>>), "`T` is non-deducible."); |
| 72 | +} |
| 73 | +{ |
| 74 | +auto f = []<typename T>(std::vector<std::vector<T>> const& x) mutable -> void{}; |
| 75 | + |
| 76 | +#line 28 "pure2-bugfix-for-deducible-parameters.cpp2" |
| 77 | + static_assert(std::is_invocable_v<decltype(std::move(f)),std::vector<std::vector<cpp2::i32>>>, "`T` is deducible."); |
| 78 | +} |
| 79 | +#line 29 "pure2-bugfix-for-deducible-parameters.cpp2" |
| 80 | +} |
| 81 | + |
| 82 | +#line 32 "pure2-bugfix-for-deducible-parameters.cpp2" |
| 83 | + template <typename T> v<T>::v(T const& x){} |
| 84 | +#line 32 "pure2-bugfix-for-deducible-parameters.cpp2" |
| 85 | + template <typename T> auto v<T>::operator=(T const& x) -> v& { |
| 86 | + return *this; } |
| 87 | + |
0 commit comments