Debian Codegraph @

gcc/testsuite/g++.dg/cpp1y/constexpr-assert2.C

raw
1 // PR c++/65985
2 // { dg-do compile { target c++14 } }
3 // { dg-skip-if "requires hosted libstdc++ for cassert" { ! hostedlib } }
4
5 #include <cassert>
6
7 class Angle
8 {
9 int degrees = 0;
10
11 constexpr auto invariant() const noexcept
12 {
13 return 0 <= degrees && degrees < 360;
14 }
15
16 public:
17 explicit constexpr Angle(int n) noexcept
18 : degrees{n % 360}
19 {
20 assert(invariant());
21 }
22
23 /* implicit */ constexpr operator auto() const noexcept
24 {
25 return degrees;
26 }
27 };
28
29 int main()
30 {
31 static_assert(Angle{360} == 0, "");
32 }