Skip to content

Commit 03fadab

Browse files
committedJul 14, 2016
cppcoreguidelines-pro-bounds-constant-array-index: crash for value dependent index in c++03 mode
Summary: When the expression is value dependent, isIntegerConstantExpr() crashes in C++03 mode with ../tools/clang/lib/AST/ExprConstant.cpp:9330: (anonymous namespace)::ICEDiag CheckICE(const clang::Expr *, const clang::ASTContext &): Assertion `!E->isValueDependent() && "Should not see value dependent exprs!"' failed. In C++11 mode, that assert does not trigger. This commit works around this in the check. We don't check value-dependent indices and instead check their specialization. Reviewers: alexfh, aaron.ballman Subscribers: nemanjai, cfe-commits Differential Revision: http://reviews.llvm.org/D22190 llvm-svn: 275461
1 parent 488f861 commit 03fadab

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed
 

‎clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ void ProBoundsConstantArrayIndexCheck::check(
6565
const MatchFinder::MatchResult &Result) {
6666
const auto *Matched = Result.Nodes.getNodeAs<Expr>("expr");
6767
const auto *IndexExpr = Result.Nodes.getNodeAs<Expr>("index");
68+
69+
if (IndexExpr->isValueDependent())
70+
return; // We check in the specialization.
71+
6872
llvm::APSInt Index;
6973
if (!IndexExpr->isIntegerConstantExpr(Index, *Result.Context, nullptr,
7074
/*isEvaluated=*/true)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: clang-tidy %s -checks=-*,cppcoreguidelines-pro-bounds-constant-array-index -- -std=c++03 | count 0
2+
3+
// Note: this test expects no diagnostics, but FileCheck cannot handle that,
4+
// hence the use of | count 0.
5+
template <int index> struct B {
6+
int get() {
7+
// The next line used to crash the check (in C++03 mode only).
8+
return x[index];
9+
}
10+
int x[3];
11+
};

0 commit comments

Comments
 (0)
Please sign in to comment.