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

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

Issue 754433003: Update from https://crrev.com/305340 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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 | « tools/clang/plugins/ChromeClassTester.cpp ('k') | tools/clang/plugins/tests/weak_ptr_factory.cpp » ('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 0a230e0fcdb106e2487c2bee2af3c88d73c6f6e4..f08ca712d5be731c8632b72dee76b3e0f969d666 100644
--- a/tools/clang/plugins/FindBadConstructsConsumer.cpp
+++ b/tools/clang/plugins/FindBadConstructsConsumer.cpp
@@ -724,28 +724,37 @@ void FindBadConstructsConsumer::CheckWeakPtrFactoryMembers(
the_end(record->field_end());
SourceLocation weak_ptr_factory_location; // Invalid initially.
for (; iter != the_end; ++iter) {
- // If we enter the loop but have already seen a matching WeakPtrFactory,
- // it means there is at least one member after the factory.
- if (weak_ptr_factory_location.isValid()) {
- diagnostic().Report(weak_ptr_factory_location,
- diag_weak_ptr_factory_order_);
- }
const TemplateSpecializationType* template_spec_type =
iter->getType().getTypePtr()->getAs<TemplateSpecializationType>();
+ bool param_is_weak_ptr_factory_to_self = false;
if (template_spec_type) {
const TemplateDecl* template_decl =
template_spec_type->getTemplateName().getAsTemplateDecl();
- if (template_decl && template_spec_type->getNumArgs() >= 1) {
+ if (template_decl && template_spec_type->getNumArgs() == 1) {
if (template_decl->getNameAsString().compare("WeakPtrFactory") == 0 &&
GetNamespace(template_decl) == "base") {
+ // Only consider WeakPtrFactory members which are specialized for the
+ // owning class.
const TemplateArgument& arg = template_spec_type->getArg(0);
if (arg.getAsType().getTypePtr()->getAsCXXRecordDecl() ==
record->getTypeForDecl()->getAsCXXRecordDecl()) {
- weak_ptr_factory_location = iter->getLocation();
+ if (!weak_ptr_factory_location.isValid()) {
+ // Save the first matching WeakPtrFactory member for the
+ // diagnostic.
+ weak_ptr_factory_location = iter->getLocation();
+ }
+ param_is_weak_ptr_factory_to_self = true;
}
}
}
}
+ // If we've already seen a WeakPtrFactory<OwningType> and this param is not
+ // one of those, it means there is at least one member after a factory.
+ if (weak_ptr_factory_location.isValid() &&
+ !param_is_weak_ptr_factory_to_self) {
+ diagnostic().Report(weak_ptr_factory_location,
+ diag_weak_ptr_factory_order_);
+ }
}
}
« no previous file with comments | « tools/clang/plugins/ChromeClassTester.cpp ('k') | tools/clang/plugins/tests/weak_ptr_factory.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698