diff options
-rw-r--r-- | lib/Sema/SemaChecking.cpp | 2 | ||||
-rw-r--r-- | test/SemaCXX/array-bounds.cpp | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 6e750c182b..aecc659485 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -3709,7 +3709,7 @@ void Sema::CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr, return; const Type* BaseType = getElementType(BaseExpr); - if (!isSubscript && BaseType != EffectiveType) { + if (BaseType != EffectiveType) { // Make sure we're comparing apples to apples when comparing index to size uint64_t ptrarith_typesize = Context.getTypeSize(EffectiveType); uint64_t array_typesize = Context.getTypeSize(BaseType); diff --git a/test/SemaCXX/array-bounds.cpp b/test/SemaCXX/array-bounds.cpp index 2bbb4776ad..e071bc7b5b 100644 --- a/test/SemaCXX/array-bounds.cpp +++ b/test/SemaCXX/array-bounds.cpp @@ -214,3 +214,15 @@ int test_more() { else return foo[5]; // expected-warning {{array index of '5' indexes past the end of an array (that contains 5 elements)}} } + +void test_pr10771() { + double foo[4096]; // expected-note {{array 'foo' declared here}} + + ((char*)foo)[sizeof(foo) - 1] = '\0'; // no-warning + *(((char*)foo) + sizeof(foo) - 1) = '\0'; // no-warning + + ((char*)foo)[sizeof(foo)] = '\0'; // expected-warning {{array index of '32768' indexes past the end of an array (that contains 32768 elements)}} + + // TODO: This should probably warn, too. + *(((char*)foo) + sizeof(foo)) = '\0'; // no-warning +} |