From c71a2c0ce03ec74391ff2b43b0a966860f23786e Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 16 Feb 2011 23:39:09 +0000 Subject: [PATCH] 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 --- lib/Sema/SemaChecking.cpp | 4 +++- test/{Sema/array-bounds.c => SemaCXX/array-bounds.cpp} | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) rename test/{Sema/array-bounds.c => SemaCXX/array-bounds.cpp} (85%) diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index a4c9eb6841..6a3ee12b17 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -3085,7 +3085,9 @@ void Sema::CheckArrayAccess(const clang::ArraySubscriptExpr *ae) { dyn_cast(ae->getBase()->IgnoreParenImpCasts()); if (!dr) return; - const VarDecl *vd = cast(dr->getDecl()); + const VarDecl *vd = dyn_cast(dr->getDecl()); + if (!vd) + return; const ConstantArrayType *cat = Context.getAsConstantArrayType(vd->getType()); if (!cat) return; diff --git a/test/Sema/array-bounds.c b/test/SemaCXX/array-bounds.cpp similarity index 85% rename from test/Sema/array-bounds.c rename to test/SemaCXX/array-bounds.cpp index b9dbe6344a..d60600fd4b 100644 --- a/test/Sema/array-bounds.c +++ b/test/SemaCXX/array-bounds.cpp @@ -14,3 +14,8 @@ int foo() { 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 class Qux { + bool test() { return sz[0] == 'a'; } +}; \ No newline at end of file -- 2.50.1