ipa-cp: Perform operations in the appropriate types (PR 118097)
[gcc.git] / gcc / testsuite / g++.dg / contracts / contracts-access1.C
blob7f6759e542150e8b71a77faee07aafaf4045c2e7
1 // ensure that that preconditions can access public, protected, and private
2 // members of the current and base classes
3 // { dg-do run }
4 // { dg-options "-std=c++2a -fcontracts -fcontract-continuation-mode=on" }
6 struct Base
8   int pub{-1};
10   virtual int b()
11     [[ pre: pub > 0 ]]
12     [[ pre: pro > 0 ]]
13     [[ pre: pri > 0 ]]
14   {
15     return pub * pro * pri;
16   }
18   protected:
19     int pro{-1};
20     int pri{-1};
23 struct Child : Base
25   int fun()
26     [[ pre: pub > 0 ]]
27     [[ pre: pro > 0 ]]
28     [[ pre: pri > 0 ]]
29   {
30     return pub * pro;
31   }
34 struct VChild : Base
36   int b()
37     [[ pre: pub > 0 ]]
38     [[ pre: pro > 0 ]]
39     [[ pre: pri > 0 ]]
40   {
41     return pub * pro;
42   }
45 template<typename B>
46 struct TChild : B
48   int fun()
49     [[ pre: B::pub > 0 ]]
50     [[ pre: B::pro > 0 ]]
51     [[ pre: B::pri > 0 ]]
52   {
53     return B::pub * B::pro;
54   }
57 struct PubBase
59   int pub{-1};
60   int pro{-1};
61   int pri{-1};
64 struct PubChild : PubBase
66   int fun()
67     [[ pre: pub > 0 ]]
68     [[ pre: pro > 0 ]]
69     [[ pre: pri > 0 ]]
70   {
71     return pub * pro;
72   }
75 template<typename B>
76 struct TPubChild : B
78   int fun()
79     [[ pre: B::pub > 0 ]]
80     [[ pre: B::pro > 0 ]]
81     [[ pre: B::pri > 0 ]]
82   {
83     return B::pub * B::pro;
84   }
87 int main()
89   Base base{};
90   base.b();
92   Child child{};
93   child.fun();
95   VChild vchild{};
96   vchild.b();
98   TChild<Base> tchild{};
99   tchild.fun();
101   PubChild pubchild{};
102   pubchild.fun();
104   TPubChild<PubBase> tpubchild;
105   tpubchild.fun();
107   return 0;
110 // { dg-skip-if "requires hosted libstdc++ for stdc++exp" { ! hostedlib } }
111 // { dg-output "contract violation in function Base::b at .*.C:11: .*(\n|\r\n|\r)" }
112 // { dg-output "contract violation in function Base::b at .*.C:12: .*(\n|\r\n|\r)" }
113 // { dg-output "contract violation in function Base::b at .*.C:13: .*(\n|\r\n|\r)" }
114 // { dg-output "contract violation in function Child::fun at .*.C:26: .*(\n|\r\n|\r)" }
115 // { dg-output "contract violation in function Child::fun at .*.C:27: .*(\n|\r\n|\r)" }
116 // { dg-output "contract violation in function Child::fun at .*.C:28: .*(\n|\r\n|\r)" }
117 // { dg-output "contract violation in function VChild::b at .*.C:37: .*(\n|\r\n|\r)" }
118 // { dg-output "contract violation in function VChild::b at .*.C:38: .*(\n|\r\n|\r)" }
119 // { dg-output "contract violation in function VChild::b at .*.C:39: .*(\n|\r\n|\r)" }
120 // { dg-output "contract violation in function TChild<Base>::fun at .*.C:49: .*(\n|\r\n|\r)" }
121 // { dg-output "contract violation in function TChild<Base>::fun at .*.C:50: .*(\n|\r\n|\r)" }
122 // { dg-output "contract violation in function TChild<Base>::fun at .*.C:51: .*(\n|\r\n|\r)" }
123 // { dg-output "contract violation in function PubChild::fun at .*.C:67: .*(\n|\r\n|\r)" }
124 // { dg-output "contract violation in function PubChild::fun at .*.C:68: .*(\n|\r\n|\r)" }
125 // { dg-output "contract violation in function PubChild::fun at .*.C:69: .*(\n|\r\n|\r)" }
126 // { dg-output "contract violation in function TPubChild<PubBase>::fun at .*.C:79: .*(\n|\r\n|\r)" }
127 // { dg-output "contract violation in function TPubChild<PubBase>::fun at .*.C:80: .*(\n|\r\n|\r)" }
128 // { dg-output "contract violation in function TPubChild<PubBase>::fun at .*.C:81: .*(\n|\r\n|\r)" }