Debian Codegraph @

gcc/testsuite/g++.dg/modules/contracts-1_b.C

raw
1 // { dg-module-do run }
2 // { dg-additional-options "-fmodules-ts -fcontracts -fcontract-continuation-mode=on" }
3 // { dg-skip-if "requires hosted libstdc++ for cstdio" { ! hostedlib } }
4
5 #include <cstdio>
6 import foo;
7
8 template<typename T>
9 bool bar_fn_pre(T n) { printf("bar fn pre(%d)\n", n); return true; }
10
11 template<typename T>
12 T bar_fn(T n)
13 [[ pre: bar_fn_pre(n) && n > 0 ]]
14 {
15 printf("%s(%d)\n", __FUNCTION__, n);
16 return n;
17 }
18
19 int main(int, char**)
20 {
21 nontemplate(5);
22 nontemplate(-5);
23 fn(5);
24 fn(-5);
25 void_fn(5);
26 void_fn(-5);
27 bar_fn(5);
28 bar_fn(-5);
29 return violation_count == 6 ? 0 : -1;
30 }
31