1 // ensure that assert contracts can be turned into compile time assumptions
2 // and that they can be used for optimization.
4 // Even though x == -1, the assert contract tells the compiler that it is
5 // safe to assume the x <= 0 branch is never taken fun can be transformed into
7 // printf("%d: test x>0\n", x);
9 // we ensure this by matching on the output and expecting a 0 return code from
10 // main -- unlike contracts-ignore2 which expects a failing return code
12 // { dg-options "-std=c++2a -fcontracts -fcontract-role=default:never,assume,ignore -O1" }
13 // { dg-skip-if "requires hosted libstdc++ for cstdio" { ! hostedlib } }
17 [[assert audit: x > 0]];
20 printf("%d: test x<=0 opt out\n", x);
25 printf("%d: test x>0\n", x);
30 int main(int, char**) {
35 // { dg-output "-1: test x>0(\n|\r\n|\r)" }