diff options
| author | Daniel Marjamaki <daniel.marjamaki@evidente.se> | 2017-02-28 14:53:50 +0000 |
|---|---|---|
| committer | Daniel Marjamaki <daniel.marjamaki@evidente.se> | 2017-02-28 14:53:50 +0000 |
| commit | 20a209e453b557525ea0ab27c47717639c889fa2 (patch) | |
| tree | 43ca90714c3616a8d28bb98bab5ac2ea06bfd119 /clang/test/SemaCXX/array-bounds.cpp | |
| parent | f830dec3f267a5353219be8e663465fbf5afd5c1 (diff) | |
| download | bcm5719-llvm-20a209e453b557525ea0ab27c47717639c889fa2.tar.gz bcm5719-llvm-20a209e453b557525ea0ab27c47717639c889fa2.zip | |
[Sema] Detect more array index out of bounds when C++ overloaded operators are used
Differential Revision: https://reviews.llvm.org/D30192
llvm-svn: 296477
Diffstat (limited to 'clang/test/SemaCXX/array-bounds.cpp')
| -rw-r--r-- | clang/test/SemaCXX/array-bounds.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/clang/test/SemaCXX/array-bounds.cpp b/clang/test/SemaCXX/array-bounds.cpp index 80b3ee42894..8ae92e76130 100644 --- a/clang/test/SemaCXX/array-bounds.cpp +++ b/clang/test/SemaCXX/array-bounds.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -verify %s +// RUN: %clang_cc1 -verify -std=c++11 %s int foo() { int x[2]; // expected-note 4 {{array 'x' declared here}} @@ -253,3 +253,19 @@ void test_rdar10916006(void) int a[128]; // expected-note {{array 'a' declared here}} a[(unsigned char)'\xA1'] = 1; // expected-warning {{array index 161 is past the end of the array}} } + +struct P { + int a; + int b; +}; + +void test_struct_array_index() { + struct P p[10]; // expected-note {{array 'p' declared here}} + p[11] = {0, 1}; // expected-warning {{array index 11 is past the end of the array (which contains 10 elements)}} +} + +int operator+(const struct P &s1, const struct P &s2); +int test_operator_overload_struct_array_index() { + struct P x[10] = {0}; // expected-note {{array 'x' declared here}} + return x[1] + x[11]; // expected-warning {{array index 11 is past the end of the array (which contains 10 elements)}} +} |

