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" }
9 #include <experimental/contract>
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)
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);
31 export int fn_in2(int x) [[ pre: pre_print(x) > 0 ]]
33 printf("%s(%d)\n", __FUNCTION__, x);
37 export int fn_iso(int n);
40 [[ pre: pre_print(n) > 0 ]];
43 [[ pre: pre_print(n) > 0 ]];
45 export int pre_print2(int n);
48 [[ pre: pre_print2(n) > 0 ]];