| 1 |
// { dg-do compile { target c++11 } } |
| 2 |
// { dg-options "-O2 -Warray-bounds" } |
| 3 |
|
| 4 |
static bool |
| 5 |
ischar(int ch) |
| 6 |
{ |
| 7 |
return (0 == (ch & ~0xff) || ~0 == (ch | 0xff)) != 0; |
| 8 |
} |
| 9 |
|
| 10 |
static bool eat(char const*& first, char const* last) |
| 11 |
{ |
| 12 |
if (first != last && ischar(*first)) { // { dg-bogus "bounds" } |
| 13 |
++first; |
| 14 |
return true; |
| 15 |
} |
| 16 |
return false; |
| 17 |
} |
| 18 |
|
| 19 |
static bool eat_two(char const*& first, char const* last) |
| 20 |
{ |
| 21 |
auto save = first; |
| 22 |
if (eat(first, last) && eat(first, last)) |
| 23 |
return true; |
| 24 |
first = save; |
| 25 |
return false; |
| 26 |
} |
| 27 |
|
| 28 |
static bool foo(char const*& first, char const* last) |
| 29 |
{ |
| 30 |
auto local_iterator = first; |
| 31 |
int i = 0; |
| 32 |
for (; i < 3; ++i) |
| 33 |
if (!eat_two(local_iterator, last)) |
| 34 |
return false; |
| 35 |
first = local_iterator; |
| 36 |
return true; |
| 37 |
} |
| 38 |
|
| 39 |
static bool test(char const* in, bool full_match = true) |
| 40 |
{ |
| 41 |
auto last = in; |
| 42 |
while (*last) |
| 43 |
++last; |
| 44 |
return foo(in, last) && (!full_match || (in == last)); // { dg-bogus "bounds" } |
| 45 |
} |
| 46 |
|
| 47 |
int main() |
| 48 |
{ |
| 49 |
return test("aa"); |
| 50 |
} |
| 51 |
|