Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/consteval-virtual5.C

raw
1 // { dg-do compile { target c++20 } }
2
3 struct B1;
4 struct B2;
5 struct D;
6
7 struct B1
8 {
9 virtual consteval const B1 *foo1 () const {return this;}
10 virtual consteval const B2 *foo2 (const D *) const;
11 };
12 struct B2
13 {
14 virtual consteval const B2 *baz1 () const {return this;}
15 virtual consteval const B1 *baz2 (const D *) const;
16 };
17
18 struct D : public B1, B2
19 {
20 virtual consteval const D *foo1 () const {return this;}
21 virtual consteval const D *foo2 (const D *d) const {return d;}
22 virtual consteval const D *baz1 () const {return this;}
23 virtual consteval const D *baz2 (const D *d) const {return d;}
24 };
25
26 consteval const B2 *B1::foo2 (const D *d) const {return d;}
27 consteval const B1 *B2::baz2 (const D *d) const {return d;}
28
29 consteval int
30 test (const B1 *b1, const B2 *b2, const D *d)
31 {
32 if (b1->foo1 () != b1)
33 return 1;
34 if (b2->baz1 () != b2)
35 return 2;
36 if (b1->foo2 (d) != b2)
37 return 3;
38 if (b2->baz2 (d) != b1)
39 return 4;
40 return 0;
41 }
42
43 consteval int
44 test (const D *d)
45 {
46 if (d->foo2 (d) != d)
47 return 11;
48 if (d->baz2 (d) != d)
49 return 12;
50 if (d->foo1 () != d)
51 return 13;
52 if (d->baz1 () != d)
53 return 14;
54 return 0;
55 }
56
57 constexpr D d;
58 constexpr auto e = test (&d, &d, &d);
59 constexpr auto f = test (&d);
60 static_assert (e == 0);
61 static_assert (f == 0);