|
|
|||
File indexing completed on 2026-05-10 08:36:21
0001 //===--- ContainerDataPointerCheck.h - clang-tidy ---------------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_CONTAINERDATAPOINTERCHECK_H 0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_CONTAINERDATAPOINTERCHECK_H 0011 0012 #include "../ClangTidyCheck.h" 0013 0014 namespace clang::tidy::readability { 0015 /// Checks whether a call to `operator[]` and `&` can be replaced with a call to 0016 /// `data()`. 0017 /// 0018 /// This only replaces the case where the offset being accessed through the 0019 /// subscript operation is a known constant 0. This avoids a potential invalid 0020 /// memory access when the container is empty. Cases where the constant is not 0021 /// explicitly zero can be addressed through the clang static analyzer, and 0022 /// those which cannot be statically identified can be caught using UBSan. 0023 class ContainerDataPointerCheck : public ClangTidyCheck { 0024 public: 0025 ContainerDataPointerCheck(StringRef Name, ClangTidyContext *Context); 0026 0027 bool isLanguageVersionSupported(const LangOptions &LO) const override { 0028 return LO.CPlusPlus11; 0029 } 0030 0031 void storeOptions(ClangTidyOptions::OptionMap &Opts) override; 0032 void registerMatchers(ast_matchers::MatchFinder *Finder) override; 0033 0034 void check(const ast_matchers::MatchFinder::MatchResult &Result) override; 0035 0036 std::optional<TraversalKind> getCheckTraversalKind() const override { 0037 return TK_IgnoreUnlessSpelledInSource; 0038 } 0039 0040 private: 0041 const std::vector<StringRef> IgnoredContainers; 0042 }; 0043 } // namespace clang::tidy::readability 0044 0045 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_CONTAINERDATAPOINTERCHECK_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|