|
| 1 | + |
| 2 | +#define CPP2_IMPORT_STD Yes |
| 3 | + |
| 4 | +//=== Cpp2 type declarations ==================================================== |
| 5 | + |
| 6 | + |
| 7 | +#include "cpp2util.h" |
| 8 | + |
| 9 | + |
| 10 | +#line 47 "pure2-bugfix-for-dependent-types.cpp2" |
| 11 | +template<typename T> class t; |
| 12 | + |
| 13 | + |
| 14 | +//=== Cpp2 type definitions and function declarations =========================== |
| 15 | + |
| 16 | +template<typename T> using identity = T; |
| 17 | + |
| 18 | +template<typename T, T::value_type V> [[nodiscard]] auto f(cpp2::in<typename T::value_type> x) -> T::value_type; |
| 19 | + |
| 20 | + |
| 21 | +#line 47 "pure2-bugfix-for-dependent-types.cpp2" |
| 22 | +template<typename T> class t { |
| 23 | +struct u_x_as_base { T::value_type x; }; |
| 24 | + |
| 25 | +#line 48 "pure2-bugfix-for-dependent-types.cpp2" |
| 26 | + public: class u: public u_x_as_base, public T::type { |
| 27 | + |
| 28 | +#line 51 "pure2-bugfix-for-dependent-types.cpp2" |
| 29 | + }; |
| 30 | + public: T::value_type x {0}; |
| 31 | +}; |
| 32 | + |
| 33 | +auto main() -> int; |
| 34 | + |
| 35 | + |
| 36 | +//=== Cpp2 function definitions ================================================= |
| 37 | + |
| 38 | + |
| 39 | +#line 3 "pure2-bugfix-for-dependent-types.cpp2" |
| 40 | +template<typename T, T::value_type V> [[nodiscard]] auto f(cpp2::in<typename T::value_type> x) -> T::value_type{ |
| 41 | + cpp2::Default.expects(cpp2::is<typename T::value_type>(x), ""); |
| 42 | + cpp2::deferred_init<typename T::value_type> y; |
| 43 | + y.construct(x); |
| 44 | + using z = T::value_type; |
| 45 | + return { typename T::value_type{x} }; |
| 46 | + |
| 47 | + // Dependent *template-id*s. |
| 48 | + static_cast<void>(typename identity<T>::value_type{});// First identifier. |
| 49 | + static_cast<void>(typename std::optional<T>::value_type{});// Non-first identifier. |
| 50 | + static_cast<void>(typename std::array<cpp2::i32,T::value>::value_type{}); |
| 51 | + static_cast<void>(typename std::array<cpp2::i32,T::value + T::value>::value_type{}); |
| 52 | + |
| 53 | + // Emitted `template`. |
| 54 | + using ptr = T*; // Also test lookup through type aliases. |
| 55 | + using nptr = cpp2::i32*; |
| 56 | + static_cast<void>(typename std::pointer_traits<ptr>::template rebind<ptr>{});// Type-only context. |
| 57 | + static_cast<void>(std::pointer_traits<nptr>::rebind<nptr>{});// Non-dependent. |
| 58 | + static_cast<void>(std::pointer_traits<nptr>::rebind<ptr>{});// Dependent on the nested template. |
| 59 | + static_cast<void>(typename std::pointer_traits<ptr>::template rebind<nptr>{});// Dependent on the outer template. |
| 60 | + // _ = :identity<typename std::pointer_traits<ptr>::rebind<ptr>> = (); // Non type-only context. Blocked on #727. |
| 61 | + |
| 62 | + // Aliases. |
| 63 | + using w = T; |
| 64 | + static_cast<void>(typename w::value_type{x}); |
| 65 | + using v = w; |
| 66 | + static_cast<void>(typename v::value_type{x}); |
| 67 | + using a = T::type; |
| 68 | + static_cast<void>(typename a::value_type{x}); |
| 69 | + |
| 70 | + { |
| 71 | + // Test that there's no prefixed `typename` to.... |
| 72 | + static_cast<void>(std::integral_constant<cpp2::i32,T::value>());// `T::value`. |
| 73 | + static_cast<void>(std::type_identity_t<T>{});// `std::type_identity_t<T>`. |
| 74 | + |
| 75 | + // Test that non-dependent names aren't emitted with `typename`. |
| 76 | + using a = std::integral_constant<cpp2::i32,0>; |
| 77 | + using b = a; |
| 78 | + using c = b; |
| 79 | + static_cast<void>(b::value_type{x}); |
| 80 | + static_cast<void>(c::value_type{x}); |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +#line 55 "pure2-bugfix-for-dependent-types.cpp2" |
| 85 | +auto main() -> int{ |
| 86 | + using zero = std::integral_constant<cpp2::i32,0>; |
| 87 | + static_cast<void>(f<zero,0>(0)); |
| 88 | + |
| 89 | + // clang-format off |
| 90 | + static_cast<void>(::t<zero>{});// clang-format on |
| 91 | + |
| 92 | + // Emitted `template` (noop, taken care of by the UFCS macro). |
| 93 | + static_cast<void>([](auto const& f) -> void{static_cast<void>(CPP2_UFCS_TEMPLATE_0(operator(), (<cpp2::i32>), f)); }([]<typename T>() -> void{})); |
| 94 | + |
| 95 | + // Nesting is not relevant to lookup. |
| 96 | + static_cast<void>([]<typename T>() -> void{static_cast<void>(typename T::value_type{}); }); |
| 97 | + static_cast<void>([]() -> void{static_cast<void>([]<typename T>() -> void{static_cast<void>(typename T::value_type{}); }); }); |
| 98 | + static_cast<void>([]() -> void{static_cast<void>([]() -> void{static_cast<void>([]<typename T>() -> void{static_cast<void>(typename T::value_type{}); }); }); }); |
| 99 | + static_cast<void>([]() -> void{static_cast<void>([]() -> void{static_cast<void>([]() -> void{static_cast<void>([]<typename T>() -> void{static_cast<void>(typename T::value_type{}); }); }); }); }); |
| 100 | + static_cast<void>([]() -> void{static_cast<void>([]() -> void{static_cast<void>([]<typename T>() -> void{static_cast<void>([]() -> void{static_cast<void>(typename T::value_type{}); }); }); }); }); |
| 101 | + static_cast<void>([]() -> void{static_cast<void>([]<typename T>() -> void{static_cast<void>([]() -> void{static_cast<void>([]() -> void{static_cast<void>(typename T::value_type{}); }); }); }); }); |
| 102 | + static_cast<void>([]<typename T>() -> void{static_cast<void>([]() -> void{static_cast<void>([]() -> void{static_cast<void>([]() -> void{static_cast<void>(typename T::value_type{}); }); }); }); }); |
| 103 | + static_cast<void>([]<typename T>() -> void{static_cast<void>([]() -> void{static_cast<void>([]() -> void{static_cast<void>([](cpp2::in<typename T::value_type> x) -> void{}); }); }); }); |
| 104 | + static_cast<void>([]<typename T>() -> void{static_cast<void>([]() -> void{static_cast<void>([](cpp2::in<typename T::value_type> x) -> void{static_cast<void>([]() -> void{}); }); }); }); |
| 105 | + static_cast<void>([]<typename T>() -> void{static_cast<void>([](cpp2::in<typename T::value_type> x) -> void{static_cast<void>([]() -> void{static_cast<void>([]() -> void{}); }); }); }); |
| 106 | + static_cast<void>([]<typename T>(cpp2::in<typename T::value_type> x) -> void{static_cast<void>([]() -> void{static_cast<void>([]() -> void{static_cast<void>([]() -> void{}); }); }); }); |
| 107 | + |
| 108 | + // Lookup. |
| 109 | + { |
| 110 | + using alias = std::integral_constant<cpp2::i32,0>; |
| 111 | + static_cast<void>(alias::value_type{0});// Non-dependent. |
| 112 | + } |
| 113 | + static_cast<void>([]<typename T>([[maybe_unused]] T const& param1) -> void{ |
| 114 | + using alias = std::integral_constant<T,0>; |
| 115 | + static_cast<void>(typename alias::value_type{0});// Dependent. |
| 116 | + { |
| 117 | + using alias = std::integral_constant<cpp2::i32,0>; |
| 118 | + static_cast<void>(typename alias::value_type{0});// Non-dependent. |
| 119 | + } |
| 120 | + }(0)); |
| 121 | +} |
| 122 | + |
0 commit comments