Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Unified Diff: tools/clang/plugins/FindBadConstructsConsumer.cpp

Issue 937833003: Fix clang plugin to catch defaulted inlined ctors/dtors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: With Chromium fixes Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/passwords/manage_passwords_test.cc ('k') | tools/clang/plugins/tests/missing_ctor.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/clang/plugins/FindBadConstructsConsumer.cpp
diff --git a/tools/clang/plugins/FindBadConstructsConsumer.cpp b/tools/clang/plugins/FindBadConstructsConsumer.cpp
index 92396e6ff0b3755de00cc9b6a12fe7ac49729f33..fe868c01de6cab10389a46321e50f0f328bd0e0a 100644
--- a/tools/clang/plugins/FindBadConstructsConsumer.cpp
+++ b/tools/clang/plugins/FindBadConstructsConsumer.cpp
@@ -283,6 +283,9 @@ void FindBadConstructsConsumer::CheckCtorDtorWeight(
for (CXXRecordDecl::ctor_iterator it = record->ctor_begin();
it != record->ctor_end();
++it) {
+ // The current check is buggy. An implicit copy constructor does not
+ // have an inline body, so this check never fires for classes with a
+ // user-declared out-of-line constructor.
if (it->hasInlineBody()) {
if (it->isCopyConstructor() &&
!record->hasUserDeclaredCopyConstructor()) {
@@ -293,6 +296,15 @@ void FindBadConstructsConsumer::CheckCtorDtorWeight(
emitWarning(it->getInnerLocStart(),
"Complex constructor has an inlined body.");
}
+ } else if (it->isInlined() && (!it->isCopyOrMoveConstructor() ||
+ it->isExplicitlyDefaulted())) {
+ // isInlined() is a more reliable check than hasInlineBody(), but
+ // unfortunately, it results in warnings for implicit copy/move
+ // constructors in the previously mentioned situation. To preserve
+ // compatibility with existing Chromium code, only warn if it's an
+ // explicitly defaulted copy or move constructor.
+ emitWarning(it->getInnerLocStart(),
+ "Complex constructor has an inlined body.");
}
}
}
@@ -306,7 +318,7 @@ void FindBadConstructsConsumer::CheckCtorDtorWeight(
"Complex class/struct needs an explicit out-of-line "
"destructor.");
} else if (CXXDestructorDecl* dtor = record->getDestructor()) {
- if (dtor->hasInlineBody()) {
+ if (dtor->isInlined()) {
emitWarning(dtor->getInnerLocStart(),
"Complex destructor has an inline body.");
}
« no previous file with comments | « chrome/browser/ui/passwords/manage_passwords_test.cc ('k') | tools/clang/plugins/tests/missing_ctor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698