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