mgehre created this revision. mgehre added reviewers: alexfh, aaron.ballman. mgehre added a subscriber: cfe-commits. Herald added a subscriber: nemanjai.
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, but maybe this should be fixed in isIntegerConstantExpr? 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: %check_clang_tidy %s cppcoreguidelines-pro-bounds-constant-array-index %t -- -- --std=c++03 +struct A { + char x[3]; +}; +template <int index> class B { + void operator()(A p1) { + // The next line used to crash the check (in C++03 mode only) + p1.x[index]; + // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use array subscript when the index is not an integer constant expression; use gsl::at() instead [cppcoreguidelines-pro-bounds-constant-array-index] + } +}; Index: clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp =================================================================== --- clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp +++ clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp @@ -66,7 +66,8 @@ const auto *Matched = Result.Nodes.getNodeAs<Expr>("expr"); const auto *IndexExpr = Result.Nodes.getNodeAs<Expr>("index"); llvm::APSInt Index; - if (!IndexExpr->isIntegerConstantExpr(Index, *Result.Context, nullptr, + if (IndexExpr->isValueDependent() + || !IndexExpr->isIntegerConstantExpr(Index, *Result.Context, nullptr, /*isEvaluated=*/true)) { SourceRange BaseRange; if (const auto *ArraySubscriptE = dyn_cast<ArraySubscriptExpr>(Matched))
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: %check_clang_tidy %s cppcoreguidelines-pro-bounds-constant-array-index %t -- -- --std=c++03 +struct A { + char x[3]; +}; +template <int index> class B { + void operator()(A p1) { + // The next line used to crash the check (in C++03 mode only) + p1.x[index]; + // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use array subscript when the index is not an integer constant expression; use gsl::at() instead [cppcoreguidelines-pro-bounds-constant-array-index] + } +}; Index: clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp =================================================================== --- clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp +++ clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp @@ -66,7 +66,8 @@ const auto *Matched = Result.Nodes.getNodeAs<Expr>("expr"); const auto *IndexExpr = Result.Nodes.getNodeAs<Expr>("index"); llvm::APSInt Index; - if (!IndexExpr->isIntegerConstantExpr(Index, *Result.Context, nullptr, + if (IndexExpr->isValueDependent() + || !IndexExpr->isIntegerConstantExpr(Index, *Result.Context, nullptr, /*isEvaluated=*/true)) { SourceRange BaseRange; if (const auto *ArraySubscriptE = dyn_cast<ArraySubscriptExpr>(Matched))
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits