]> granicus.if.org Git - clang/commitdiff
Fix assertion failure in -Warray-bounds on template parameters used as arrays.
authorTed Kremenek <kremenek@apple.com>
Wed, 16 Feb 2011 23:39:09 +0000 (23:39 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 16 Feb 2011 23:39:09 +0000 (23:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125693 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaChecking.cpp
test/SemaCXX/array-bounds.cpp [moved from test/Sema/array-bounds.c with 85% similarity]

index a4c9eb68412b5bccb67c8f805758c0ff59f2e2d1..6a3ee12b1706ef3d5c400ade52cbc0d1317afe11 100644 (file)
@@ -3085,7 +3085,9 @@ void Sema::CheckArrayAccess(const clang::ArraySubscriptExpr *ae) {
     dyn_cast<DeclRefExpr>(ae->getBase()->IgnoreParenImpCasts());
   if (!dr)
     return;
-  const VarDecl *vd = cast<VarDecl>(dr->getDecl());
+  const VarDecl *vd = dyn_cast<VarDecl>(dr->getDecl());
+  if (!vd)
+    return;
   const ConstantArrayType *cat = Context.getAsConstantArrayType(vd->getType());
   if (!cat)
     return;
similarity index 85%
rename from test/Sema/array-bounds.c
rename to test/SemaCXX/array-bounds.cpp
index b9dbe6344a0964630f06bf456af195c58a3f82c8..d60600fd4bc61aec0a8819c64929a02c660b5f71 100644 (file)
@@ -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 <char *sz> class Qux {
+  bool test() { return sz[0] == 'a'; }
+};
\ No newline at end of file