|
| 1 | +//type:fp |
| 2 | +//use_system_includes: true |
| 3 | +//edg_header_pack: exp_meta |
| 4 | +//require:DO_IL_LOWERING 1 |
| 5 | + |
| 6 | +/* |
| 7 | +std::meta::type_of of a nonstatic member function is a plain function type |
| 8 | +([dcl.fct]): the class is not part of it, but the cv-qualifiers, the |
| 9 | +ref-qualifier, and the exception specification are. So it compares equal to |
| 10 | +the reflection of that function type, and the spliced type matches partial |
| 11 | +specializations for function types. |
| 12 | +*/ |
| 13 | + |
| 14 | +#include <experimental/meta> |
| 15 | + |
| 16 | +using namespace std::meta; |
| 17 | + |
| 18 | +struct M { |
| 19 | + int f(int, double); |
| 20 | + void g() const noexcept; |
| 21 | + void h() volatile &&; |
| 22 | + static int s(int); |
| 23 | + void d(int = 1); |
| 24 | + void e(this M &, int); |
| 25 | + virtual void v(); |
| 26 | +}; |
| 27 | + |
| 28 | +static_assert(type_of(^^M::f) == ^^int(int, double)); |
| 29 | +static_assert(type_of(^^M::g) == ^^void() const noexcept); |
| 30 | +static_assert(type_of(^^M::h) == ^^void() volatile &&); |
| 31 | +static_assert(type_of(^^M::s) == ^^int(int)); |
| 32 | +static_assert(type_of(^^M::d) == ^^void(int)); |
| 33 | +static_assert(type_of(^^M::e) == ^^void(M &, int)); |
| 34 | +static_assert(type_of(^^M::v) == ^^void()); |
| 35 | +static_assert(is_function_type(type_of(^^M::f))); |
| 36 | + |
| 37 | +template <typename> struct Kind { static constexpr int value = 0; }; |
| 38 | +template <typename R, typename... A> struct Kind<R(A...)> { |
| 39 | + static constexpr int value = 1; |
| 40 | +}; |
| 41 | +template <typename R, typename... A> struct Kind<R(A...) const noexcept> { |
| 42 | + static constexpr int value = 2; |
| 43 | +}; |
| 44 | +template <typename R, typename... A> struct Kind<R(A...) volatile &&> { |
| 45 | + static constexpr int value = 3; |
| 46 | +}; |
| 47 | + |
| 48 | +static_assert(Kind<typename[:type_of(^^M::f):]>::value == 1); |
| 49 | +static_assert(Kind<typename[:type_of(^^M::g):]>::value == 2); |
| 50 | +static_assert(Kind<typename[:type_of(^^M::h):]>::value == 3); |
| 51 | + |
| 52 | +// The function type gives back the pointer-to-member type. |
| 53 | +using F = [:type_of(^^M::f):]; |
| 54 | +using G = [:type_of(^^M::g):]; |
| 55 | +using PF = F M::*; |
| 56 | +using PG = G M::*; |
| 57 | +static_assert(dealias(^^PF) == ^^int (M::*)(int, double)); |
| 58 | +static_assert(dealias(^^PG) == ^^void (M::*)() const noexcept); |
| 59 | + |
| 60 | +// The result does not depend on where type_of is evaluated. |
| 61 | +consteval info type_of_g() { return type_of(^^M::g); } |
| 62 | +constexpr info g_type = type_of_g(); |
| 63 | +static_assert(g_type == type_of(^^M::g)); |
0 commit comments