jbcoe updated this revision to Diff 66541. jbcoe added a comment. static `join` function is no longer a function template.
https://reviews.llvm.org/D23008 Files: clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h test/clang-tidy/cppcoreguidelines-special-member-functions.cpp
Index: test/clang-tidy/cppcoreguidelines-special-member-functions.cpp =================================================================== --- test/clang-tidy/cppcoreguidelines-special-member-functions.cpp +++ test/clang-tidy/cppcoreguidelines-special-member-functions.cpp @@ -50,3 +50,18 @@ DeletesCopyDefaultsMove &operator=(DeletesCopyDefaultsMove &&) = default; ~DeletesCopyDefaultsMove() = default; }; + +template <typename T> +struct TemplateClass { + TemplateClass() = default; + TemplateClass(const TemplateClass &); + TemplateClass &operator=(const TemplateClass &); + TemplateClass(TemplateClass &&); + TemplateClass &operator=(TemplateClass &&); + ~TemplateClass(); +}; + +// Multiple instantiations of a class template will trigger multiple matches for defined special members. +// This should not cause problems. +TemplateClass<int> InstantiationWithInt; +TemplateClass<double> InstantiationWithDouble; Index: clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h =================================================================== --- clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h +++ clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h @@ -1,4 +1,4 @@ -//===--- SpecialMemberFunctionsCheck.h - clang-tidy-------------------*- C++ -*-===// +//===--- SpecialMemberFunctionsCheck.h - clang-tidy--------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -41,15 +41,11 @@ using ClassDefId = std::pair<SourceLocation, std::string>; - using ClassDefiningSpecialMembersMap = llvm::DenseMap<ClassDefId, llvm::SmallVector<SpecialMemberFunctionKind, 5>>; + using ClassDefiningSpecialMembersMap = + llvm::DenseMap<ClassDefId, + llvm::SmallSetVector<SpecialMemberFunctionKind, 5>>; private: - - static llvm::StringRef toString(SpecialMemberFunctionKind K); - - static std::string join(llvm::ArrayRef<SpecialMemberFunctionKind> SMFS, - llvm::StringRef AndOr); - ClassDefiningSpecialMembersMap ClassWithSpecialMembers; }; @@ -65,7 +61,7 @@ struct DenseMapInfo< clang::tidy::cppcoreguidelines::SpecialMemberFunctionsCheck::ClassDefId> { using ClassDefId = - clang::tidy::cppcoreguidelines::SpecialMemberFunctionsCheck::ClassDefId; + clang::tidy::cppcoreguidelines::SpecialMemberFunctionsCheck::ClassDefId; static inline ClassDefId getEmptyKey() { return ClassDefId( Index: clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp =================================================================== --- clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp +++ clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp @@ -43,25 +43,26 @@ this); } -llvm::StringRef SpecialMemberFunctionsCheck::toString( - SpecialMemberFunctionsCheck::SpecialMemberFunctionKind K) { +static llvm::StringRef +toString(SpecialMemberFunctionsCheck::SpecialMemberFunctionKind K) { switch (K) { - case SpecialMemberFunctionKind::Destructor: + case SpecialMemberFunctionsCheck::SpecialMemberFunctionKind::Destructor: return "a destructor"; - case SpecialMemberFunctionKind::CopyConstructor: + case SpecialMemberFunctionsCheck::SpecialMemberFunctionKind::CopyConstructor: return "a copy constructor"; - case SpecialMemberFunctionKind::CopyAssignment: + case SpecialMemberFunctionsCheck::SpecialMemberFunctionKind::CopyAssignment: return "a copy assignment operator"; - case SpecialMemberFunctionKind::MoveConstructor: + case SpecialMemberFunctionsCheck::SpecialMemberFunctionKind::MoveConstructor: return "a move constructor"; - case SpecialMemberFunctionKind::MoveAssignment: + case SpecialMemberFunctionsCheck::SpecialMemberFunctionKind::MoveAssignment: return "a move assignment operator"; } llvm_unreachable("Unhandled SpecialMemberFunctionKind"); } -std::string SpecialMemberFunctionsCheck::join( - llvm::ArrayRef<SpecialMemberFunctionKind> SMFS, llvm::StringRef AndOr) { +static std::string +join(ArrayRef<SpecialMemberFunctionsCheck::SpecialMemberFunctionKind> SMFS, + llvm::StringRef AndOr) { assert(!SMFS.empty() && "List of defined or undefined members should never be empty."); @@ -97,7 +98,7 @@ for (const auto &KV : Matchers) if (Result.Nodes.getNodeAs<CXXMethodDecl>(KV.first)) - ClassWithSpecialMembers[ID].push_back(KV.second); + ClassWithSpecialMembers[ID].insert(KV.second); } void SpecialMemberFunctionsCheck::onEndOfTranslationUnit() { @@ -112,7 +113,7 @@ } for (const auto &C : ClassWithSpecialMembers) { - ArrayRef<SpecialMemberFunctionKind> DefinedSpecialMembers = C.second; + const auto &DefinedSpecialMembers = C.second; if (DefinedSpecialMembers.size() == AllSpecialMembers.size()) continue; @@ -124,7 +125,7 @@ std::back_inserter(UndefinedSpecialMembers)); diag(C.first.first, "class '%0' defines %1 but does not define %2") - << C.first.second << join(DefinedSpecialMembers, " and ") + << C.first.second << join(DefinedSpecialMembers.getArrayRef(), " and ") << join(UndefinedSpecialMembers, " or "); } }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits