Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:19

0001 //===--- ReservedIdentifierCheck.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_BUGPRONE_RESERVEDIDENTIFIERCHECK_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_RESERVEDIDENTIFIERCHECK_H
0011 
0012 #include "../utils/RenamerClangTidyCheck.h"
0013 #include <optional>
0014 #include <string>
0015 #include <vector>
0016 
0017 namespace clang::tidy::bugprone {
0018 
0019 /// Checks for usages of identifiers reserved for use by the implementation.
0020 ///
0021 /// The C and C++ standards both reserve the following names for such use:
0022 /// * identifiers that begin with an underscore followed by an uppercase letter;
0023 /// * identifiers in the global namespace that begin with an underscore.
0024 ///
0025 /// The C standard additionally reserves names beginning with a double
0026 /// underscore, while the C++ standard strengthens this to reserve names with a
0027 /// double underscore occurring anywhere.
0028 ///
0029 /// For the user-facing documentation see:
0030 /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/reserved-identifier.html
0031 class ReservedIdentifierCheck final : public RenamerClangTidyCheck {
0032   const bool Invert;
0033   const std::vector<StringRef> AllowedIdentifiersRaw;
0034   const llvm::SmallVector<llvm::Regex> AllowedIdentifiers;
0035 
0036 public:
0037   ReservedIdentifierCheck(StringRef Name, ClangTidyContext *Context);
0038 
0039   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
0040 
0041 private:
0042   std::optional<FailureInfo>
0043   getDeclFailureInfo(const NamedDecl *Decl,
0044                      const SourceManager &SM) const override;
0045   std::optional<FailureInfo>
0046   getMacroFailureInfo(const Token &MacroNameTok,
0047                       const SourceManager &SM) const override;
0048   DiagInfo getDiagInfo(const NamingCheckId &ID,
0049                        const NamingCheckFailure &Failure) const override;
0050   llvm::SmallVector<llvm::Regex> parseAllowedIdentifiers() const;
0051 };
0052 
0053 } // namespace clang::tidy::bugprone
0054 
0055 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_RESERVEDIDENTIFIERCHECK_H