OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "BlinkGCPluginConsumer.h" | 5 #include "BlinkGCPluginConsumer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "CheckDispatchVisitor.h" | 10 #include "CheckDispatchVisitor.h" |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 NoteField(&field.second, diag_field_requires_finalization_note_); | 658 NoteField(&field.second, diag_field_requires_finalization_note_); |
659 } | 659 } |
660 | 660 |
661 void BlinkGCPluginConsumer::CheckUnneededFinalization(RecordInfo* info) { | 661 void BlinkGCPluginConsumer::CheckUnneededFinalization(RecordInfo* info) { |
662 if (!HasNonEmptyFinalizer(info)) | 662 if (!HasNonEmptyFinalizer(info)) |
663 ReportClassDoesNotRequireFinalization(info); | 663 ReportClassDoesNotRequireFinalization(info); |
664 } | 664 } |
665 | 665 |
666 bool BlinkGCPluginConsumer::HasNonEmptyFinalizer(RecordInfo* info) { | 666 bool BlinkGCPluginConsumer::HasNonEmptyFinalizer(RecordInfo* info) { |
667 CXXDestructorDecl* dtor = info->record()->getDestructor(); | 667 CXXDestructorDecl* dtor = info->record()->getDestructor(); |
| 668 |
| 669 // If the destructor is virtual (or one of the bases are by way of the |
| 670 // recursive call below), consider this class as having a non-empty |
| 671 // finalizer. Not doing so runs counter to standard C++ reflexes like |
| 672 // |
| 673 // class A : public GarbageCollectedMixin { |
| 674 // public: |
| 675 // virtual ~A() { }; |
| 676 // virtual void f() = 0; |
| 677 // }; |
| 678 // class B : public GarbageCollectedFinalized<B>, public A { |
| 679 // USING_GARBAGE_COLLECTED_MIXIN(B); |
| 680 // public: |
| 681 // ~B() override { } |
| 682 // void f() override { } |
| 683 // }; |
| 684 // |
| 685 // and it is considered a step too far to report a warning for such |
| 686 // explicit usage of empty destructors. |
| 687 if (dtor && dtor->isVirtual()) |
| 688 return true; |
| 689 |
668 if (dtor && dtor->isUserProvided()) { | 690 if (dtor && dtor->isUserProvided()) { |
669 if (!dtor->hasBody() || !EmptyStmtVisitor::isEmpty(dtor->getBody())) | 691 if (!dtor->hasBody() || !EmptyStmtVisitor::isEmpty(dtor->getBody())) |
670 return true; | 692 return true; |
671 } | 693 } |
| 694 |
| 695 if (info->GetFinalizeDispatchMethod()) |
| 696 return true; |
| 697 |
672 for (auto& base : info->GetBases()) | 698 for (auto& base : info->GetBases()) |
673 if (HasNonEmptyFinalizer(base.second.info())) | 699 if (HasNonEmptyFinalizer(base.second.info())) |
674 return true; | 700 return true; |
675 | 701 |
676 for (auto& field : info->GetFields()) | 702 for (auto& field : info->GetFields()) |
677 if (field.second.edge()->NeedsFinalization()) | 703 if (field.second.edge()->NeedsFinalization()) |
678 return true; | 704 return true; |
679 | 705 |
680 return false; | 706 return false; |
681 } | 707 } |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1184 void BlinkGCPluginConsumer::NoteField(FieldDecl* field, unsigned note) { | 1210 void BlinkGCPluginConsumer::NoteField(FieldDecl* field, unsigned note) { |
1185 ReportDiagnostic(field->getLocStart(), note) << field; | 1211 ReportDiagnostic(field->getLocStart(), note) << field; |
1186 } | 1212 } |
1187 | 1213 |
1188 void BlinkGCPluginConsumer::NoteOverriddenNonVirtualTrace( | 1214 void BlinkGCPluginConsumer::NoteOverriddenNonVirtualTrace( |
1189 CXXMethodDecl* overridden) { | 1215 CXXMethodDecl* overridden) { |
1190 ReportDiagnostic(overridden->getLocStart(), | 1216 ReportDiagnostic(overridden->getLocStart(), |
1191 diag_overridden_non_virtual_trace_note_) | 1217 diag_overridden_non_virtual_trace_note_) |
1192 << overridden; | 1218 << overridden; |
1193 } | 1219 } |
OLD | NEW |