ipa-cp: Perform operations in the appropriate types (PR 118097)
[gcc.git] / gcc / testsuite / g++.dg / contracts / contracts-constexpr1.C
blobf37d3d390ff63ff8fef4dc236bef05a87af4cbc8
1 // ensure that passing pre/post do not affect constexpr functions
2 // ensure that failing pre/post generate an error at runtime in constexpr funcs
3 // { dg-do run }
4 // { dg-options "-std=c++20 -fcontracts -fcontract-continuation-mode=on" }
6 constexpr int wfun(int a)
7   [[ pre: a > 0 ]]
8   [[ post r: r > 0 ]]
10   return a;
13 constexpr int ffun(int a)
14   [[ pre: a > 0 ]]
15   [[ post r: r > 0 ]]
17   return a;
20 template<typename T>
21 constexpr int tfun(T a)
22   [[ pre: a > 0 ]]
23   [[ post r: r > 0 ]]
25   return a;
28 template<typename T>
29 constexpr int wtfun(T a)
30   [[ pre: a > 0 ]]
31   [[ post r: r > 0 ]]
33   return a;
36 template<typename T>
37 constexpr int ftfun(T a)
38   [[ pre: a > 0 ]]
39   [[ post r: r > 0 ]]
41   return a;
44 constexpr int explicitfn(int a)
45   [[ pre ignore: a > 0 ]]
46   [[ pre check_maybe_continue: a > 0 ]]
47   [[ post ignore r: r > 0 ]]
48   [[ post check_maybe_continue r: r > 0 ]]
50   return a;
53 int main(int, char **) {
54   constexpr int a = wfun(10);
55   int b = ffun(-10);
56   constexpr int c = wtfun(10);
57   int d = ftfun(-10);
59   int e = explicitfn(-10);
61   int z = ftfun(-10.0);
63   return 0;
66 // { dg-skip-if "requires hosted libstdc++ for stdc++exp" { ! hostedlib } }
67 // { dg-output "contract violation in function ffun at .*.C:14: .*(\n|\r\n|\r)" }
68 // { dg-output "contract violation in function ffun at .*.C:15: .*(\n|\r\n|\r)" }
69 // { dg-output "contract violation in function ftfun<int> at .*.C:38: .*(\n|\r\n|\r)" }
70 // { dg-output "contract violation in function ftfun<int> at .*.C:39: .*(\n|\r\n|\r)" }
71 // { dg-output "contract violation in function explicitfn at .*.C:46: .*(\n|\r\n|\r)" }
72 // { dg-output "contract violation in function explicitfn at .*.C:48: .*(\n|\r\n|\r)" }
73 // { dg-output "contract violation in function ftfun<double> at .*.C:38: .*(\n|\r\n|\r)" }
74 // { dg-output "contract violation in function ftfun<double> at .*.C:39: .*(\n|\r\n|\r)" }