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