[PATCH] D117205: [clang-tidy] Support custom fix hint for cppcoreguidelines-pro-bounds-constant-array-index
Nathan James via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Jan 15 07:14:59 PST 2022
njames93 added inline comments.
================
Comment at: clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp:26
+ utils::IncludeSorter::IS_LLVM)),
+ FixHint(Options.get("FixHint", "gsl::at()")) {}
----------------
Should elide the braces here for the option and insert them at the warning stage.
================
Comment at: clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp:79-82
auto Diag = diag(Matched->getExprLoc(),
- "do not use array subscript when the index is "
- "not an integer constant expression; use gsl::at() "
- "instead");
- if (!GslHeader.empty()) {
+ std::string("do not use array subscript when the index is "
+ "not an integer constant expression; use ") +
+ FixHint + " instead");
----------------
================
Comment at: clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp:84
+
+ if (!GslHeader.empty() && (FixHint == "gsl::at()")) {
Diag << FixItHint::CreateInsertion(BaseRange.getBegin(), "gsl::at(")
----------------
This restriction on only offering a fix if using `gsl::at` seem a little too restrictive, especially when you factor that the GslHeader is defaulted to an empty string and that is already required for a fix to be emitted.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D117205/new/
https://reviews.llvm.org/D117205
More information about the cfe-commits
mailing list