clang-tools 19.0.0git
SpecialMemberFunctionsCheck.h
Go to the documentation of this file.
1//===--- SpecialMemberFunctionsCheck.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_CPPCOREGUIDELINES_SPECIAL_MEMBER_FUNCTIONS_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_SPECIAL_MEMBER_FUNCTIONS_H
11
12#include "../ClangTidyCheck.h"
13
14#include "llvm/ADT/DenseMapInfo.h"
15
17
18/// Checks for classes where some, but not all, of the special member functions
19/// are defined.
20///
21/// For the user-facing documentation see:
22/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/special-member-functions.html
24public:
26 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
27 return LangOpts.CPlusPlus;
28 }
29 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
30 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
31 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
32 void onEndOfTranslationUnit() override;
33 std::optional<TraversalKind> getCheckTraversalKind() const override {
34 return TK_IgnoreUnlessSpelledInSource;
35 }
36 enum class SpecialMemberFunctionKind : uint8_t {
44 };
45
49
50 bool operator==(const SpecialMemberFunctionData &Other) const {
51 return (Other.FunctionKind == FunctionKind) &&
52 (Other.IsDeleted == IsDeleted);
53 }
54 };
55
56 using ClassDefId = std::pair<SourceLocation, std::string>;
57
59 llvm::DenseMap<ClassDefId,
60 llvm::SmallVector<SpecialMemberFunctionData, 5>>;
61
62private:
63 void checkForMissingMembers(
64 const ClassDefId &ID,
65 llvm::ArrayRef<SpecialMemberFunctionData> DefinedMembers);
66
67 const bool AllowMissingMoveFunctions;
68 const bool AllowSoleDefaultDtor;
69 const bool AllowMissingMoveFunctionsWhenCopyIsDeleted;
70 ClassDefiningSpecialMembersMap ClassWithSpecialMembers;
71};
72
73} // namespace clang::tidy::cppcoreguidelines
74
75namespace llvm {
76/// Specialization of DenseMapInfo to allow ClassDefId objects in DenseMaps
77/// FIXME: Move this to the corresponding cpp file as is done for
78/// clang-tidy/readability/IdentifierNamingCheck.cpp.
79template <>
80struct DenseMapInfo<
81 clang::tidy::cppcoreguidelines::SpecialMemberFunctionsCheck::ClassDefId> {
82 using ClassDefId =
84
85 static inline ClassDefId getEmptyKey() {
86 return {DenseMapInfo<clang::SourceLocation>::getEmptyKey(),
87 "EMPTY"};
88 }
89
90 static inline ClassDefId getTombstoneKey() {
91 return {DenseMapInfo<clang::SourceLocation>::getTombstoneKey(),
92 "TOMBSTONE"};
93 }
94
95 static unsigned getHashValue(ClassDefId Val) {
96 assert(Val != getEmptyKey() && "Cannot hash the empty key!");
97 assert(Val != getTombstoneKey() && "Cannot hash the tombstone key!");
98
99 std::hash<ClassDefId::second_type> SecondHash;
100 return Val.first.getHashValue() + SecondHash(Val.second);
101 }
102
103 static bool isEqual(const ClassDefId &LHS, const ClassDefId &RHS) {
104 if (RHS == getEmptyKey())
105 return LHS == getEmptyKey();
106 if (RHS == getTombstoneKey())
107 return LHS == getTombstoneKey();
108 return LHS == RHS;
109 }
110};
111
112} // namespace llvm
113
114#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_SPECIAL_MEMBER_FUNCTIONS_H
llvm::SmallString< 256U > Name
Base class for all clang-tidy checks.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Checks for classes where some, but not all, of the special member functions are defined.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Override this to disable registering matchers and PP callbacks if an invalid language version is bein...
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
llvm::DenseMap< ClassDefId, llvm::SmallVector< SpecialMemberFunctionData, 5 > > ClassDefiningSpecialMembersMap
std::optional< TraversalKind > getCheckTraversalKind() const override
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Some operations such as code completion produce a set of candidates.
llvm::StringMap< ClangTidyValue > OptionMap
clang::tidy::cppcoreguidelines::SpecialMemberFunctionsCheck::ClassDefId ClassDefId