ReservedIdentifierCheck.h 2.1 KB

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