Ted Kremenek | a0125d8 | 2011-02-16 01:57:07 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -verify %s |
| 2 | |
| 3 | int foo() { |
Ted Kremenek | bac7737 | 2011-02-16 22:08:28 +0000 | [diff] [blame] | 4 | int x[2]; // expected-note 4 {{array 'x' declared here}} |
| 5 | int y[2]; // expected-note 2 {{array 'y' declared here}} |
Ted Kremenek | a0125d8 | 2011-02-16 01:57:07 +0000 | [diff] [blame] | 6 | int *p = &y[2]; // no-warning |
| 7 | (void) sizeof(x[2]); // no-warning |
Ted Kremenek | 8fd0a5d | 2011-02-16 04:01:44 +0000 | [diff] [blame] | 8 | y[2] = 2; // expected-warning{{array index of '2' indexes past the end of an array (that contains 2 elements)}} |
| 9 | return x[2] + // expected-warning{{array index of '2' indexes past the end of an array (that contains 2 elements)}} |
| 10 | y[-1] + // expected-warning{{array index of '-1' indexes before the beginning of the array}} |
| 11 | x[sizeof(x)] + // expected-warning{{array index of '8' indexes past the end of an array (that contains 2 elements)}} |
| 12 | x[sizeof(x) / sizeof(x[0])] + // expected-warning{{array index of '2' indexes past the end of an array (that contains 2 elements)}} |
Ted Kremenek | a0125d8 | 2011-02-16 01:57:07 +0000 | [diff] [blame] | 13 | x[sizeof(x) / sizeof(x[0]) - 1] + // no-warning |
Ted Kremenek | 8fd0a5d | 2011-02-16 04:01:44 +0000 | [diff] [blame] | 14 | x[sizeof(x[2])]; // expected-warning{{array index of '4' indexes past the end of an array (that contains 2 elements)}} |
Ted Kremenek | a0125d8 | 2011-02-16 01:57:07 +0000 | [diff] [blame] | 15 | } |
| 16 | |
Ted Kremenek | c71a2c0 | 2011-02-16 23:39:09 +0000 | [diff] [blame^] | 17 | // This code example tests that -Warray-bounds works with arrays that |
| 18 | // are template parameters. |
| 19 | template <char *sz> class Qux { |
| 20 | bool test() { return sz[0] == 'a'; } |
| 21 | }; |