comparison gcc/testsuite/g++.dg/cpp2a/constexpr-virtual8.C @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents
children
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
1 // P1064R0
2 // { dg-do compile }
3 // { dg-options "-std=c++2a" }
4
5 template<typename T>
6 struct X1
7 {
8 virtual T f() const = 0;
9 };
10
11 struct X2: public X1<int>
12 {
13 constexpr virtual int f() const { return 2; }
14 };
15
16 struct X3: public X2
17 {
18 virtual int f() const { return 3; }
19 };
20
21 struct X4: public X3
22 {
23 constexpr virtual int f() const { return 4; }
24 };
25
26 constexpr int (X1<int>::*pf)() const = &X1<int>::f;
27
28 constexpr X2 x2;
29 static_assert(x2.f() == 2);
30 static_assert((x2.*pf)() == 2);
31
32 constexpr X1<int> const& r2 = x2;
33 static_assert(r2.f() == 2);
34 static_assert((r2.*pf)() == 2);
35
36 constexpr X1<int> const* p2 = &x2;
37 static_assert(p2->f() == 2);
38 static_assert((p2->*pf)() == 2);
39
40 constexpr X4 x4;
41 static_assert(x4.f() == 4);
42 static_assert((x4.*pf)() == 4);
43
44 constexpr X1<int> const& r4 = x4;
45 static_assert(r4.f() == 4);
46 static_assert((r4.*pf)() == 4);
47
48 constexpr X1<int> const* p4 = &x4;
49 static_assert(p4->f() == 4);
50 static_assert((p4->*pf)() == 4);