[clang-tools-extra] r257177 - Disable part of the misc-move-constructor-init checker when the check is enabled through cert-oop11-cpp. The CERT guideline does not cover moveable parameters as part of the OOP11-CPP recommendation, just copy construction from move constructors.
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 8 07:50:51 PST 2016
Author: aaronballman
Date: Fri Jan 8 09:50:51 2016
New Revision: 257177
URL: http://llvm.org/viewvc/llvm-project?rev=257177&view=rev
Log:
Disable part of the misc-move-constructor-init checker when the check is enabled through cert-oop11-cpp. The CERT guideline does not cover moveable parameters as part of the OOP11-CPP recommendation, just copy construction from move constructors.
Added:
clang-tools-extra/trunk/test/clang-tidy/cert-oop11-cpp.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h
clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.h
Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp?rev=257177&r1=257176&r2=257177&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp Fri Jan 8 09:50:51 2016
@@ -233,6 +233,10 @@ GlobList &ClangTidyContext::getChecksFil
return *CheckFilter;
}
+bool ClangTidyContext::isCheckEnabled(StringRef CheckName) const {
+ return CheckFilter->contains(CheckName);
+}
+
/// \brief Store a \c ClangTidyError.
void ClangTidyContext::storeError(const ClangTidyError &Error) {
Errors.push_back(Error);
Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h?rev=257177&r1=257176&r2=257177&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h Fri Jan 8 09:50:51 2016
@@ -161,6 +161,9 @@ public:
/// The \c CurrentFile can be changed using \c setCurrentFile.
GlobList &getChecksFilter();
+ /// \brief Returns true if the check name is enabled for the \c CurrentFile.
+ bool isCheckEnabled(StringRef CheckName) const;
+
/// \brief Returns global options.
const ClangTidyGlobalOptions &getGlobalOptions() const;
Modified: clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.cpp?rev=257177&r1=257176&r2=257177&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.cpp Fri Jan 8 09:50:51 2016
@@ -42,7 +42,8 @@ MoveConstructorInitCheck::MoveConstructo
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
IncludeStyle(IncludeSorter::parseIncludeStyle(
- Options.get("IncludeStyle", "llvm"))) {}
+ Options.get("IncludeStyle", "llvm"))),
+ UseCERTSemantics(Context->isCheckEnabled("cert-oop11-cpp")) {}
void MoveConstructorInitCheck::registerMatchers(MatchFinder *Finder) {
// Only register the matchers for C++11; the functionality currently does not
@@ -67,21 +68,26 @@ void MoveConstructorInitCheck::registerM
hasDeclaration(cxxRecordDecl(hasMethod(cxxConstructorDecl(
isMoveConstructor(), unless(isDeleted()))))),
matchers::isExpensiveToCopy()));
- Finder->addMatcher(
- cxxConstructorDecl(
- allOf(
- unless(isMoveConstructor()),
- hasAnyConstructorInitializer(withInitializer(cxxConstructExpr(
- hasDeclaration(cxxConstructorDecl(isCopyConstructor())),
- hasArgument(
- 0, declRefExpr(
- to(parmVarDecl(
- hasType(
- NonConstValueMovableAndExpensiveToCopy))
- .bind("movable-param")))
- .bind("init-arg")))))))
- .bind("ctor-decl"),
- this);
+
+ // This checker is also used to implement cert-oop11-cpp, but when using that
+ // form of the checker, we do not want to diagnose movable parameters.
+ if (!UseCERTSemantics)
+ Finder->addMatcher(
+ cxxConstructorDecl(
+ allOf(
+ unless(isMoveConstructor()),
+ hasAnyConstructorInitializer(withInitializer(cxxConstructExpr(
+ hasDeclaration(cxxConstructorDecl(isCopyConstructor())),
+ hasArgument(
+ 0,
+ declRefExpr(
+ to(parmVarDecl(
+ hasType(
+ NonConstValueMovableAndExpensiveToCopy))
+ .bind("movable-param")))
+ .bind("init-arg")))))))
+ .bind("ctor-decl"),
+ this);
}
void MoveConstructorInitCheck::check(const MatchFinder::MatchResult &Result) {
Modified: clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.h?rev=257177&r1=257176&r2=257177&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.h Fri Jan 8 09:50:51 2016
@@ -39,6 +39,7 @@ private:
std::unique_ptr<IncludeInserter> Inserter;
const IncludeSorter::IncludeStyle IncludeStyle;
+ const bool UseCERTSemantics;
};
} // namespace tidy
Added: clang-tools-extra/trunk/test/clang-tidy/cert-oop11-cpp.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cert-oop11-cpp.cpp?rev=257177&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cert-oop11-cpp.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/cert-oop11-cpp.cpp Fri Jan 8 09:50:51 2016
@@ -0,0 +1,21 @@
+// RUN: %check_clang_tidy %s cert-oop11-cpp %t -- -- -std=c++11
+
+struct B {
+ B(B&&) noexcept = default;
+
+ B(const B &) = default;
+ B& operator=(const B&) = default;
+ ~B() {}
+};
+
+struct D {
+ B b;
+
+ // CHECK-MESSAGES: :[[@LINE+1]]:14: warning: move constructor initializes class member by calling a copy constructor [cert-oop11-cpp]
+ D(D &&d) : b(d.b) {}
+
+ // This should not produce a diagnostic because it is not covered under
+ // the CERT guideline for OOP11-CPP. However, this will produce a diagnostic
+ // under misc-move-constructor-init.
+ D(B b) : b(b) {}
+};
More information about the cfe-commits
mailing list