Debian Codegraph @

gcc/testsuite/g++.dg/contracts/contracts-friend1.C

raw
1 // ensure contracts on friend declarations are a complete class context
2 // { dg-do run }
3 // { dg-options "-std=c++2a -fcontracts -fcontract-continuation-mode=on" }
4
5 struct X {
6 friend void fn0(X x) [[ pre: x.a > 0 ]] { }
7
8 friend void fn2(X x);
9 static void fns0(X x) [[ pre: x.a > 0 ]] { }
10 static void fns1(X x) [[ pre: x.a > 0 ]];
11 static void fns2(X x);
12
13 friend void fn(X &x) { x.a = -5; }
14
15 private:
16 int a{10};
17 };
18
19 void fn2(X x) [[ pre: x.a > 0 ]] { }
20 void X::fns1(X x) { }
21 void X::fns2(X x) [[ pre: x.a > 0 ]] { }
22
23 int main(int, char**) {
24 X x;
25 fn(x); // no contract
26
27 fn0(x);
28 fn2(x);
29
30 X::fns0(x);
31 X::fns1(x);
32 X::fns2(x);
33 return 0;
34 }
35
36 // { dg-skip-if "requires hosted libstdc++ for stdc++exp" { ! hostedlib } }
37 // { dg-output "contract violation in function fn0 at .*.C:6: .*(\n|\r\n|\r)" }
38 // { dg-output "contract violation in function fn2 at .*.C:19: .*(\n|\r\n|\r)" }
39 // { dg-output "contract violation in function X::fns0 at .*.C:9: .*(\n|\r\n|\r)" }
40 // { dg-output "contract violation in function X::fns1 at .*.C:10: .*(\n|\r\n|\r)" }
41 // { dg-output "contract violation in function X::fns2 at .*.C:21: .*(\n|\r\n|\r)" }