clang-tools 22.0.0git
ProBoundsAvoidUncheckedContainerAccess.h
Go to the documentation of this file.
1//===--- ProBoundsAvoidUncheckedContainerAccess.h - clang-tidy --*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_BOUNDS_AVOID_UNCHECKED_CONTAINER_ACCESS_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_BOUNDS_AVOID_UNCHECKED_CONTAINER_ACCESS_H
11
12#include "../ClangTidyCheck.h"
13
15
16/// Flags calls to operator[] in STL containers and suggests replacing it with
17/// safe alternatives.
18///
19/// See
20/// https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#slcon3-avoid-bounds-errors
21/// For the user-facing documentation see:
22/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/pro-bounds-avoid-unchecked-container-access.html
24public:
26 ClangTidyContext *Context);
27 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
28 return LangOpts.CPlusPlus;
29 }
30 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
31 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
32 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
33
35
36private:
37 // A list of class names that are excluded from the warning
38 std::vector<llvm::StringRef> ExcludedClasses;
39 // Setting which fix to suggest
40 FixModes FixMode;
41 llvm::StringRef FixFunction;
42 llvm::StringRef FixFunctionEmptyArgs;
43};
44} // namespace clang::tidy::cppcoreguidelines
45
46namespace clang::tidy {
47template <>
49 cppcoreguidelines::ProBoundsAvoidUncheckedContainerAccess::FixModes> {
50 static ArrayRef<std::pair<
52 StringRef>>
54};
55} // namespace clang::tidy
56#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_BOUNDS_AVOID_UNCHECKED_CONTAINER_ACCESS_H
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
llvm::StringMap< ClangTidyValue > OptionMap
static ArrayRef< std::pair< cppcoreguidelines::ProBoundsAvoidUncheckedContainerAccess::FixModes, StringRef > > getEnumMapping()
This class should be specialized by any enum type that needs to be converted to and from an llvm::Str...