https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123237

--- Comment #11 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Better:

// PR c++/123237
// { dg-do compile { target c++26 } }
// { dg-additional-options "-freflection" }

using info = decltype(^^::);

template<unsigned>
struct A { };

template<typename T>
struct B {
  T t;
  constexpr T fn () { return 42; }
};

struct Y {
  int i;
  using type = int;
};

namespace N {
  struct NY {
    int i;
  };
}

template<typename T>
using U = [:^^T:];

template<info R>
constexpr auto f1 (typename [:R:] x) { return x; }

template<info R>
constexpr auto f2 (typename [:R:]::NY x) { return x; }

template<info R>
constexpr auto f3 () -> A<sizeof(typename [:R:])> { return {}; }

template<info R>
constexpr auto f4 () -> A<sizeof([:R:])> { return {}; }

template<info R>
constexpr auto f5 () -> decltype([:R:]) { return {}; }

template<typename T>
constexpr auto f6 (U<T> y) { return y; }

template<info R>
constexpr auto f7 (typename [:R:]<0> x) { return x; }

template<typename T>
constexpr auto f8 (typename [:^^T:] x) { return x; }

template<info R>
constexpr typename [:R:] f9 (int i) { return i; }

template<typename T>
constexpr T foo (T t) { return t; }

template<info R>
constexpr auto f10 () -> decltype(template [:R:](42)) { return {}; }

template<info R>
constexpr auto f11 (A<template [:R:](42)> a) { return a; }

template<typename T>
consteval info id () { return ^^T; }

template<typename T>
constexpr typename [:id<T>():] f12 () { return 42; }

template<info R>
constexpr auto f13 (typename [:R:]::type x) { return x; }

template<info R>
constexpr auto f14 () -> [:R:] { return {}; }

template<typename T, info R>
constexpr auto f15 () -> decltype(T{}.[:R:]) { return {}; }

template<typename T, info R>
constexpr auto f16 () -> decltype(T{}.template [:R:]()) { return {}; }

template<info O, info M>
constexpr auto f17 () -> decltype(typename [:O:]{}.[:M:]) { return {}; }

template<info M>
constexpr auto f18 () -> decltype(Y{}.[:M:]) { return {}; }

template<template<typename> class T>
constexpr auto f19 () -> [:^^T:]<int> { return {}; }

int i;

void
g ()
{
  // splice-type-spec
  f1<^^Y>(Y{ 42 });
  // splice-scope-spec
  f2<^^N>(N::NY{ 42 });
  // splice-type-spec
  f3<^^int>();
  // splice-expr
  f4<^^i>();
  f5<^^i>();
  // splice-type-spec
  f6<Y>(Y{42});
  f7<^^A>(A<0>{});
  f8<int>(42);
  f9<^^int>(42);
  // splice-expr
  f10<^^foo<int>>();
  f11<^^foo<int>>(A<42>{});
  // splice-type-spec
  f12<int>();
  // splice-scope-spec
  f13<^^Y>(42);
  // splice-type-spec
  f14<^^int>();
  f14<^^A<1>>();
  // splice-expr
  f15<Y, ^^Y::i>();
  f15<B<int>, ^^B<int>::t>();
  f16<B<int>, ^^B<int>::fn>();
  // splice-type-spec
  f17<^^Y, ^^Y::i>();
  // splice-expr
  f18<^^Y::i>();
  // splice-type-spec
  f19<B>();
}

Reply via email to