view gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const14.C @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents
children
line wrap: on
line source

// PR c++/91264
// { dg-do compile { target c++14 } }

struct F {
  const int f;
  constexpr F() : f(9) { }
};

struct C {
  int n;
  const F f;
  constexpr C() : n(1) { n = 66; }
};

struct A {
  int r;
  const C c;
  constexpr A() : r(11) { r = 14; const_cast<C &>(c).n = 42; } // { dg-error "modifying a const object" }
};

struct D {
  const A a;
  constexpr D() { } // { dg-message "in .constexpr. expansion of" }
};

struct E {
  const D d;
  constexpr E() { } // { dg-message "in .constexpr. expansion of" }
};

struct B {
  const E e;
  constexpr B(bool) { } // { dg-message "in .constexpr. expansion of" }
};

constexpr B b(false); // { dg-message "in .constexpr. expansion of" }
// { dg-message "originally declared" "" { target *-*-* } .-1 }
static_assert(b.e.d.a.c.n == 2, ""); // { dg-error "non-constant condition" }