This revision was automatically updated to reflect the committed changes. Closed by commit rL275461: cppcoreguidelines-pro-bounds-constant-array-index: crash for value dependent… (authored by mgehre).
Changed prior to commit: https://reviews.llvm.org/D22190?vs=63795&id=64030#toc Repository: rL LLVM https://reviews.llvm.org/D22190 Files: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index-c++03.cpp Index: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp +++ clang-tools-extra/trunk/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: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index-c++03.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index-c++03.cpp +++ clang-tools-extra/trunk/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-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp +++ clang-tools-extra/trunk/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: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index-c++03.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index-c++03.cpp +++ clang-tools-extra/trunk/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]; +};
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits