|
| 1 | +identity: <T> type == T; |
| 2 | + |
| 3 | +f: <T, V: T::value_type> (x: T::value_type) -> T::value_type = { |
| 4 | + [[assert: x is T::value_type]] |
| 5 | + y: T::value_type; |
| 6 | + y = x; |
| 7 | + z: type == T::value_type; |
| 8 | + return (:T::value_type = x); |
| 9 | + |
| 10 | + // Dependent *template-id*s. |
| 11 | + _ = :identity<T>::value_type = (); // First identifier. |
| 12 | + _ = :std::optional<T>::value_type = (); // Non-first identifier. |
| 13 | + _ = :std::array<i32, T::value>::value_type = (); |
| 14 | + _ = :std::array<i32, T::value + T::value>::value_type = (); |
| 15 | + |
| 16 | + // Emitted `template`. |
| 17 | + ptr: type == * T; // Needed, pending #502. |
| 18 | + nptr: type == * i32; // Needed, pending #502. |
| 19 | + _ = :std::pointer_traits<ptr>::rebind<ptr> = (); // Type-only context. |
| 20 | + _ = :std::pointer_traits<nptr>::rebind<nptr> = (); // Non-dependent. |
| 21 | + _ = :std::pointer_traits<nptr>::rebind<ptr> = (); // Dependent on the nested template. |
| 22 | + _ = :std::pointer_traits<ptr>::rebind<nptr> = (); // Dependent on the outer template. |
| 23 | + // Uncomment once `typename` is supported for template arguments. |
| 24 | + // _ = :identity<typename std::pointer_traits<ptr>::rebind<ptr>> = (); // Non type-only context. |
| 25 | + |
| 26 | + // Aliases. |
| 27 | + w: type == T; |
| 28 | + _ = :w::value_type = x; |
| 29 | + v: type == w; |
| 30 | + _ = :v::value_type = x; |
| 31 | + a: type == T::type; |
| 32 | + _ = :a::value_type = x; |
| 33 | + |
| 34 | + { |
| 35 | + // Test that there's no prefixed `typename` to.... |
| 36 | + _ = std::integral_constant<i32, T::value>(); // `T::value`. |
| 37 | + _ = :std::type_identity_t<T> = (); // `std::type_identity_t<T>`. |
| 38 | + |
| 39 | + // Test that non-dependent names aren't emitted with `typename`. |
| 40 | + a: type == std::integral_constant<i32, 0>; |
| 41 | + b: type == a; |
| 42 | + c: type == b; |
| 43 | + _ = :b::value_type = x; |
| 44 | + _ = :c::value_type = x; |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +t: @struct <T: type> type = { |
| 49 | + u: @struct type = { |
| 50 | + x: T::value_type = (); |
| 51 | + this: T::type = (); |
| 52 | + } |
| 53 | + x: T::value_type = 0; |
| 54 | +} |
| 55 | + |
| 56 | +main: () = { |
| 57 | + zero: type == std::integral_constant<i32, 0>; |
| 58 | + _ = f<zero, 0>(0); |
| 59 | + |
| 60 | + // clang-format off |
| 61 | + _ = : ::t<zero> = (); // clang-format on |
| 62 | + |
| 63 | + // Emitted `template` (noop, taken care of by the UFCS macro). |
| 64 | + _ = :(f) = { _ = f.operator() <i32>(); }(:<T> () = {}); |
| 65 | + |
| 66 | + // Nesting is irrelevant. |
| 67 | + _ = :<T> () = { _ = :T::value_type = (); }; |
| 68 | + _ = :() = { _ = :<T> () = { _ = :T::value_type = (); }; }; |
| 69 | + _ = :() = { _ = :() = { _ = :<T> () = { _ = :T::value_type = (); }; }; }; |
| 70 | + _ = :() = { _ = :() = { _ = :() = { _ = :<T> () = { _ = :T::value_type = (); }; }; }; }; |
| 71 | + _ = :() = { _ = :() = { _ = :<T> () = { _ = :() = { _ = :T::value_type = (); }; }; }; }; |
| 72 | + _ = :() = { _ = :<T> () = { _ = :() = { _ = :() = { _ = :T::value_type = (); }; }; }; }; |
| 73 | + _ = :<T> () = { _ = :() = { _ = :() = { _ = :() = { _ = :T::value_type = (); }; }; }; }; |
| 74 | + _ = :<T> () = { _ = :() = { _ = :() = { _ = :(x: T::value_type) = {}; }; }; }; |
| 75 | + _ = :<T> () = { _ = :() = { _ = :(x: T::value_type) = { _ = :() = {}; }; }; }; |
| 76 | + _ = :<T> () = { _ = :(x: T::value_type) = { _ = :() = { _ = :() = {}; }; }; }; |
| 77 | + _ = :<T> (x: T::value_type) = { _ = :() = { _ = :() = { _ = :() = {}; }; }; }; |
| 78 | + |
| 79 | + // Lookup. |
| 80 | + { |
| 81 | + alias: type == std::integral_constant<i32, 0>; |
| 82 | + _ = :alias::value_type = 0; // Non-dependent. |
| 83 | + } |
| 84 | + _ = :<T> (_: T) = { |
| 85 | + alias: type == std::integral_constant<T, 0>; |
| 86 | + _ = :alias::value_type = 0; // Dependent. |
| 87 | + { |
| 88 | + alias: type == std::integral_constant<i32, 0>; |
| 89 | + _ = :alias::value_type = 0; // Non-dependent. |
| 90 | + } |
| 91 | + }(0); |
| 92 | +} |
0 commit comments