clang-tools 17.0.0git
ReservedIdentifierCheck.h
Go to the documentation of this file.
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 <optional>
14#include <string>
15#include <vector>
16
17namespace clang::tidy::bugprone {
18
19/// Checks for usages of identifiers reserved for use by the implementation.
20///
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.
24///
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.
28///
29/// For the user-facing documentation see:
30/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/reserved-identifier.html
32 const bool Invert;
33 const std::vector<StringRef> AllowedIdentifiers;
34
35public:
37
38 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
39
40private:
41 std::optional<FailureInfo>
42 getDeclFailureInfo(const NamedDecl *Decl,
43 const SourceManager &SM) const override;
44 std::optional<FailureInfo>
45 getMacroFailureInfo(const Token &MacroNameTok,
46 const SourceManager &SM) const override;
47 DiagInfo getDiagInfo(const NamingCheckId &ID,
48 const NamingCheckFailure &Failure) const override;
49};
50
51} // namespace clang::tidy::bugprone
52
53#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_RESERVEDIDENTIFIERCHECK_H
const FunctionDecl * Decl
Token Name
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Base class for clang-tidy checks that want to flag declarations and/or macros for renaming based on c...
std::pair< SourceLocation, std::string > NamingCheckId
Checks for usages of identifiers reserved for use by the implementation.
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
llvm::StringMap< ClangTidyValue > OptionMap
Represents customized diagnostic text and how arguments should be applied.
Holds an identifier name check failure, tracking the kind of the identifier, its possible fixup and t...