Fortran: Fix PR 47485.
[gcc.git] / gcc / testsuite / g++.dg / warn / Winfinite-recursion-3.C
blobee0be59d723bb9bd38047308ac52065cffa59061
1 /* PR middle-end/88232 - Please implement -Winfinite-recursion
2    { dg-do compile }
3    Explicit { dg-require-effective-target exceptions_enabled } to avoid verify compiler messages FAILs for '-fno-exceptions'.
4    { dg-options "-Wall -Winfinite-recursion" } */
6 typedef __SIZE_TYPE__ size_t;
8 /* Might throw.  */
9 void f ();
11 /* Verify a warning is issued even though a call to f() might throw,
12    breaking the infinite recursion.  */
14 void warn_f_call_r (int  n)   // { dg-warning "-Winfinite-recursion" }
16   if (n > 7)
17     f ();
18   warn_f_call_r (n - 1);      // { dg-message "recursive call" }
21 void warn_f_do_while_call_r (int n)    // { dg-warning "-Winfinite-recursion" }
23   f ();
24   do
25     {
26       f ();
27       warn_f_do_while_call_r (n - 1);  // { dg-message "recursive call" }
28     }
29   while (1);
33 struct X
35   X (int);
36   ~X ();
39 /* Verify a warning even though the X ctor might throw, breaking
40    the recursion.  Using possible throwing to suppress the warning
41    would make it pretty much useless in C++.  */
43 int warn_class_with_ctor (int n)    // { dg-warning "-Winfinite-recursion" }
45   X x (n);
46   return n + warn_class_with_ctor (n - 1);
50 int nowarn_throw (int n)
52   if (n > 7)
53     throw "argument too big";
55   return n + nowarn_throw (n - 1);
59 /* Verify call operator new doesn't suppress the warning even though
60    it might throw.  */
62 extern int* eipa[];
64 void warn_call_new (int i)          // { dg-warning "-Winfinite-recursion" }
66   eipa[i] = new int;
68   warn_call_new (i - 1);
71 /* Verify a recursive call to operator new.  */
73 void* operator new[] (size_t n)     // { dg-warning "-Winfinite-recursion" }
75   char *p = new char[n + sizeof (n)];   // { dg-message "recursive call" }
76   *(size_t*)p = n;
77   return p + sizeof n;