|
|
|||
File indexing completed on 2026-05-10 08:36:21
0001 //===--- ContainerSizeEmptyCheck.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_CONTAINERSIZEEMPTYCHECK_H 0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_CONTAINERSIZEEMPTYCHECK_H 0011 0012 #include "../ClangTidyCheck.h" 0013 #include <vector> 0014 0015 namespace clang::tidy::readability { 0016 0017 /// Checks whether a call to the `size()`/`length()` method can be replaced with 0018 /// a call to `empty()`. 0019 /// 0020 /// The emptiness of a container should be checked using the `empty()` method 0021 /// instead of the `size()`/`length()` method. It shows clearer intent to use 0022 /// `empty()`. Furthermore some containers (for example, a `std::forward_list`) 0023 /// may implement the `empty()` method but not implement the `size()` or 0024 /// `length()` method. Using `empty()` whenever possible makes it easier to 0025 /// switch to another container in the future. 0026 class ContainerSizeEmptyCheck : public ClangTidyCheck { 0027 public: 0028 ContainerSizeEmptyCheck(StringRef Name, ClangTidyContext *Context); 0029 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override { 0030 return LangOpts.CPlusPlus; 0031 } 0032 void registerMatchers(ast_matchers::MatchFinder *Finder) override; 0033 void check(const ast_matchers::MatchFinder::MatchResult &Result) override; 0034 void storeOptions(ClangTidyOptions::OptionMap &Opts) override; 0035 std::optional<TraversalKind> getCheckTraversalKind() const override { 0036 return TK_IgnoreUnlessSpelledInSource; 0037 } 0038 0039 private: 0040 std::vector<llvm::StringRef> ExcludedComparisonTypes; 0041 }; 0042 0043 } // namespace clang::tidy::readability 0044 0045 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_CONTAINERSIZEEMPTYCHECK_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|