blob: d60600fd4bc61aec0a8819c64929a02c660b5f71 [file] [log] [blame]
Ted Kremeneka0125d82011-02-16 01:57:07 +00001// RUN: %clang_cc1 -verify %s
2
3int foo() {
Ted Kremenekbac77372011-02-16 22:08:28 +00004 int x[2]; // expected-note 4 {{array 'x' declared here}}
5 int y[2]; // expected-note 2 {{array 'y' declared here}}
Ted Kremeneka0125d82011-02-16 01:57:07 +00006 int *p = &y[2]; // no-warning
7 (void) sizeof(x[2]); // no-warning
Ted Kremenek8fd0a5d2011-02-16 04:01:44 +00008 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 Kremeneka0125d82011-02-16 01:57:07 +000013 x[sizeof(x) / sizeof(x[0]) - 1] + // no-warning
Ted Kremenek8fd0a5d2011-02-16 04:01:44 +000014 x[sizeof(x[2])]; // expected-warning{{array index of '4' indexes past the end of an array (that contains 2 elements)}}
Ted Kremeneka0125d82011-02-16 01:57:07 +000015}
16
Ted Kremenekc71a2c02011-02-16 23:39:09 +000017// This code example tests that -Warray-bounds works with arrays that
18// are template parameters.
19template <char *sz> class Qux {
20 bool test() { return sz[0] == 'a'; }
21};