Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 1 | //===--- ReservedIdentifierCheck.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_BUGPRONE_RESERVEDIDENTIFIERCHECK_H |
| 10 | #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_RESERVEDIDENTIFIERCHECK_H |
| 11 | |
| 12 | #include "../utils/RenamerClangTidyCheck.h" |
| 13 | #include "llvm/ADT/Optional.h" |
| 14 | #include <string> |
| 15 | #include <vector> |
| 16 | |
| 17 | namespace clang { |
| 18 | namespace tidy { |
| 19 | namespace bugprone { |
| 20 | |
| 21 | /// Checks for usages of identifiers reserved for use by the implementation. |
| 22 | /// |
| 23 | /// The C and C++ standards both reserve the following names for such use: |
| 24 | /// * identifiers that begin with an underscore followed by an uppercase letter; |
| 25 | /// * identifiers in the global namespace that begin with an underscore. |
| 26 | /// |
| 27 | /// The C standard additionally reserves names beginning with a double |
| 28 | /// underscore, while the C++ standard strengthens this to reserve names with a |
| 29 | /// double underscore occurring anywhere. |
| 30 | /// |
| 31 | /// For the user-facing documentation see: |
| 32 | /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-reserved-identifier.html |
| 33 | class ReservedIdentifierCheck final : public RenamerClangTidyCheck { |
| 34 | const bool Invert; |
| 35 | const std::vector<std::string> AllowedIdentifiers; |
| 36 | |
| 37 | public: |
| 38 | ReservedIdentifierCheck(StringRef Name, ClangTidyContext *Context); |
| 39 | |
| 40 | void storeOptions(ClangTidyOptions::OptionMap &Opts) override; |
| 41 | |
| 42 | private: |
| 43 | llvm::Optional<FailureInfo> |
| 44 | GetDeclFailureInfo(const NamedDecl *Decl, |
| 45 | const SourceManager &SM) const override; |
| 46 | llvm::Optional<FailureInfo> |
| 47 | GetMacroFailureInfo(const Token &MacroNameTok, |
| 48 | const SourceManager &SM) const override; |
| 49 | DiagInfo GetDiagInfo(const NamingCheckId &ID, |
| 50 | const NamingCheckFailure &Failure) const override; |
| 51 | }; |
| 52 | |
| 53 | } // namespace bugprone |
| 54 | } // namespace tidy |
| 55 | } // namespace clang |
| 56 | |
| 57 | #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_RESERVEDIDENTIFIERCHECK_H |