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)) {
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)) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits