c++: Implement P2615 'Meaningful Exports' [PR107688]
[official-gcc.git] / gcc / testsuite / g++.dg / modules / contracts-1_a.C
blob723726451f4e9e7d03e29c4d22e26f4b90873648
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 module;
5 #include <cstdio>
6 #include <experimental/contract>
7 export module foo;
8 // { dg-module-cmi foo }
10 export int violation_count{0};
11 export extern "C++" void handle_contract_violation(const std::experimental::contract_violation &violation)
13   violation_count++;
14   printf("violation_count: %d\n", violation_count);
17 export int nontemplate(int n)
18   [[ pre: n > 0 ]]
19   [[ post r: r > 0 ]]
21   return -n;
24 export
25 template<typename T>
26 T fn(T n)
27   [[ pre: n > 0 ]]
28   [[ post r: r > 0 ]]
30   printf("%s(%d)\n", __FUNCTION__, n);
31   return n;
34 export
35 template<typename T>
36 void void_fn(T n)
37   [[ pre: n < 0 ]]
39   printf("%s(%d)\n", __FUNCTION__, n);
42 export void foo_fn()
44   fn(5);