diff options
author | Ted Kremenek <kremenek@apple.com> | 2011-02-16 23:39:09 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2011-02-16 23:39:09 +0000 |
commit | c71a2c0ce03ec74391ff2b43b0a966860f23786e (patch) | |
tree | 4f9ef51ca97d56eaffac7ba0f3db58be5312673e /test/SemaCXX/array-bounds.cpp | |
parent | 05318d835e8beb16ac6bdd2c0db0ab6a922f35cf (diff) |
Fix assertion failure in -Warray-bounds on template parameters used as arrays.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125693 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX/array-bounds.cpp')
-rw-r--r-- | test/SemaCXX/array-bounds.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/SemaCXX/array-bounds.cpp b/test/SemaCXX/array-bounds.cpp new file mode 100644 index 0000000000..d60600fd4b --- /dev/null +++ b/test/SemaCXX/array-bounds.cpp @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -verify %s + +int foo() { + int x[2]; // expected-note 4 {{array 'x' declared here}} + int y[2]; // expected-note 2 {{array 'y' declared here}} + int *p = &y[2]; // no-warning + (void) sizeof(x[2]); // no-warning + y[2] = 2; // expected-warning{{array index of '2' indexes past the end of an array (that contains 2 elements)}} + return x[2] + // expected-warning{{array index of '2' indexes past the end of an array (that contains 2 elements)}} + y[-1] + // expected-warning{{array index of '-1' indexes before the beginning of the array}} + x[sizeof(x)] + // expected-warning{{array index of '8' indexes past the end of an array (that contains 2 elements)}} + x[sizeof(x) / sizeof(x[0])] + // expected-warning{{array index of '2' indexes past the end of an array (that contains 2 elements)}} + x[sizeof(x) / sizeof(x[0]) - 1] + // no-warning + x[sizeof(x[2])]; // expected-warning{{array index of '4' indexes past the end of an array (that contains 2 elements)}} +} + +// This code example tests that -Warray-bounds works with arrays that +// are template parameters. +template <char *sz> class Qux { + bool test() { return sz[0] == 'a'; } +};
\ No newline at end of file |