c++: Implement P2615 'Meaningful Exports' [PR107688]
[official-gcc.git] / gcc / testsuite / g++.dg / modules / contracts-2_a.C
blob3d78c412d4684425ddedbdfc5ac653fd5927b048
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 }
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)
17   violation_count++;
18   violation_line_sum += violation.line_number () * violation_count;
19   printf("violation: %d %d\n", violation_count, violation_line_sum);
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; }
26 export int fn_in1(int n) [[ pre: pre_print(n) > 0 ]]
28   printf("%s blah (%d)\n", __FUNCTION__, n);
29   return n;
31 export int fn_in2(int x) [[ pre: pre_print(x) > 0 ]]
33   printf("%s(%d)\n", __FUNCTION__, x);
34   return x;
37 export int fn_iso(int n);
39 export int fn1(int n)
40   [[ pre: pre_print(n) > 0 ]];
42 export int fn2(int n)
43   [[ pre: pre_print(n) > 0 ]];
45 export int pre_print2(int n);
47 export int fn3(int n)
48   [[ pre: pre_print2(n) > 0 ]];