| 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" } */ |
| 5 |
|
| 6 |
typedef __SIZE_TYPE__ size_t; |
| 7 |
|
| 8 |
/* Might throw. */ |
| 9 |
void f (); |
| 10 |
|
| 11 |
/* Verify a warning is issued even though a call to f() might throw, |
| 12 |
breaking the infinite recursion. */ |
| 13 |
|
| 14 |
void warn_f_call_r (int n) // { dg-warning "-Winfinite-recursion" } |
| 15 |
{ |
| 16 |
if (n > 7) |
| 17 |
f (); |
| 18 |
warn_f_call_r (n - 1); // { dg-message "recursive call" } |
| 19 |
} |
| 20 |
|
| 21 |
void warn_f_do_while_call_r (int n) // { dg-warning "-Winfinite-recursion" } |
| 22 |
{ |
| 23 |
f (); |
| 24 |
do |
| 25 |
{ |
| 26 |
f (); |
| 27 |
warn_f_do_while_call_r (n - 1); // { dg-message "recursive call" } |
| 28 |
} |
| 29 |
while (1); |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
struct X |
| 34 |
{ |
| 35 |
X (int); |
| 36 |
~X (); |
| 37 |
}; |
| 38 |
|
| 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++. */ |
| 42 |
|
| 43 |
int warn_class_with_ctor (int n) // { dg-warning "-Winfinite-recursion" } |
| 44 |
{ |
| 45 |
X x (n); |
| 46 |
return n + warn_class_with_ctor (n - 1); |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
int nowarn_throw (int n) |
| 51 |
{ |
| 52 |
if (n > 7) |
| 53 |
throw "argument too big"; |
| 54 |
|
| 55 |
return n + nowarn_throw (n - 1); |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
/* Verify call operator new doesn't suppress the warning even though |
| 60 |
it might throw. */ |
| 61 |
|
| 62 |
extern int* eipa[]; |
| 63 |
|
| 64 |
void warn_call_new (int i) // { dg-warning "-Winfinite-recursion" } |
| 65 |
{ |
| 66 |
eipa[i] = new int; |
| 67 |
|
| 68 |
warn_call_new (i - 1); |
| 69 |
} |
| 70 |
|
| 71 |
/* Verify a recursive call to operator new. */ |
| 72 |
|
| 73 |
void* operator new[] (size_t n) // { dg-warning "-Winfinite-recursion" } |
| 74 |
{ |
| 75 |
char *p = new char[n + sizeof (n)]; // { dg-message "recursive call" } |
| 76 |
*(size_t*)p = n; |
| 77 |
return p + sizeof n; |
| 78 |
} |