Debian Codegraph @

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

raw
1 // Basic test to ensure that guarded templates correctly serialize and
2 // deserialize their contracts through the CMI.
3 // { dg-additional-options "-fmodules-ts -fcontracts -fcontract-continuation-mode=on" }
4 // { dg-skip-if "requires hosted libstdc++ for cstdio" { ! hostedlib } }
5 module;
6 #include <cstdio>
7 #include <experimental/contract>
8 export module foo;
9 // { dg-module-cmi foo }
10
11 export int violation_count{0};
12 export extern "C++" void handle_contract_violation(const std::experimental::contract_violation &violation)
13 {
14 violation_count++;
15 printf("violation_count: %d\n", violation_count);
16 }
17
18 export int nontemplate(int n)
19 [[ pre: n > 0 ]]
20 [[ post r: r > 0 ]]
21 {
22 return -n;
23 }
24
25 export
26 template<typename T>
27 T fn(T n)
28 [[ pre: n > 0 ]]
29 [[ post r: r > 0 ]]
30 {
31 printf("%s(%d)\n", __FUNCTION__, n);
32 return n;
33 }
34
35 export
36 template<typename T>
37 void void_fn(T n)
38 [[ pre: n < 0 ]]
39 {
40 printf("%s(%d)\n", __FUNCTION__, n);
41 }
42