Debian Codegraph @

gcc/testsuite/g++.dg/modules/contracts-2_a.C

raw
1 // Basic test to ensure that guarded function contracts are correctly
2 // serialized and deserialized through the CMI.
3 // This also tries to ensure that entities referenced in a function's
4 // contracts are correctly marked as a dependency of the function itself and
5 // serialized in the correct order.
6 // { dg-additional-options "-fmodules-ts -fcontracts -fcontract-role=default:maybe,maybe,ignore" }
7 module;
8 #include <cstdio>
9 #include <experimental/contract>
10 export module foo;
11 // { dg-module-cmi foo }
12
13 export int violation_count{0};
14 export int violation_line_sum{0};
15 export extern "C++" void handle_contract_violation(const std::experimental::contract_violation &violation)
16 {
17 violation_count++;
18 violation_line_sum += violation.line_number () * violation_count;
19 printf("violation: %d %d\n", violation_count, violation_line_sum);
20 }
21
22 export int fn2(int n);
23 export int fn_in2(int n);
24 export int pre_print(int n) { printf("pre_print(%d)\n", n); return n; }
25
26 export int fn_in1(int n) [[ pre: pre_print(n) > 0 ]]
27 {
28 printf("%s blah (%d)\n", __FUNCTION__, n);
29 return n;
30 }
31 export int fn_in2(int x) [[ pre: pre_print(x) > 0 ]]
32 {
33 printf("%s(%d)\n", __FUNCTION__, x);
34 return x;
35 }
36
37 export int fn_iso(int n);
38
39 export int fn1(int n)
40 [[ pre: pre_print(n) > 0 ]];
41
42 export int fn2(int n)
43 [[ pre: pre_print(n) > 0 ]];
44
45 export int pre_print2(int n);
46
47 export int fn3(int n)
48 [[ pre: pre_print2(n) > 0 ]];
49
50 // { dg-skip-if "requires hosted libstdc++ for cstdio" { ! hostedlib } }