[PATCH] D22190: cppcoreguidelines-pro-bounds-constant-array-index: crash for value dependent index in c++03 mode

Matthias Gehre via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 13 05:08:13 PDT 2016


mgehre updated this revision to Diff 63795.
mgehre added a comment.

Suppress diagnostics if index is value-dependent. Emit them in specializations.


http://reviews.llvm.org/D22190

Files:
  clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
  test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index-c++03.cpp

Index: test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index-c++03.cpp
===================================================================
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index-c++03.cpp
@@ -0,0 +1,11 @@
+// RUN: clang-tidy %s -checks=-*,cppcoreguidelines-pro-bounds-constant-array-index -- -std=c++03 | count 0
+
+// Note: this test expects no diagnostics, but FileCheck cannot handle that,
+// hence the use of | count 0.
+template <int index> struct B {
+  int get() {
+    // The next line used to crash the check (in C++03 mode only)
+    return x[index];
+  }
+  int x[3];
+};
Index: clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
===================================================================
--- clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
+++ clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
@@ -65,6 +65,10 @@
     const MatchFinder::MatchResult &Result) {
   const auto *Matched = Result.Nodes.getNodeAs<Expr>("expr");
   const auto *IndexExpr = Result.Nodes.getNodeAs<Expr>("index");
+
+  if (IndexExpr->isValueDependent())
+    return; // we check in the specialization
+
   llvm::APSInt Index;
   if (!IndexExpr->isIntegerConstantExpr(Index, *Result.Context, nullptr,
                                         /*isEvaluated=*/true)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22190.63795.patch
Type: text/x-patch
Size: 1369 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160713/3deed90d/attachment.bin>


More information about the cfe-commits mailing list