view gcc/testsuite/g++.dg/cpp1y/pr79937-5.C @ 19:2b5abeee2509 default tip

update gcc11
author anatofuz
date Mon, 25 May 2020 07:50:57 +0900
parents
children
line wrap: on
line source

// PR c++/79937
// This is a constexpr adaptation of pr79937-3.C and pr79937-4.C.
// { dg-do compile { target c++14 } }

struct X {
  unsigned i;
  unsigned n = i;
};

constexpr X bar(X x) {
  return x;
}

struct Y
{
  static constexpr Y bar(Y y) { return y; }
  unsigned i;
  unsigned n = bar(Y{2,i}).n;
};

constexpr X x { 1, bar(X{2}).n };
static_assert(x.n == 2, "");

constexpr Y y { 1 };
static_assert(y.n == 1, "");

struct Z {
  unsigned i;
  unsigned n = i;
  unsigned m = i;
};

constexpr Z
baz (Z z)
{
  if (z.i != 1 || z.n != 2 || z.m != 1)
    __builtin_abort ();
  return z;
}

constexpr Z z = baz (Z {1, Z {2}.n});
static_assert(z.i == 1 && z.n == 2 && z.m == 1, "");