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

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

Issue 1816283003: chrome style plugin: Don't crash when checking class weight. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add test comments Created 4 years, 9 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 | « no previous file | tools/clang/plugins/tests/class_with_incomplete_type.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 d1fc29df7ce5117d8a58fcf762917d730d7eddc0..5385cc83b7ce7a5ac59b2495241d26afdf8948cc 100644
--- a/tools/clang/plugins/FindBadConstructsConsumer.cpp
+++ b/tools/clang/plugins/FindBadConstructsConsumer.cpp
@@ -48,13 +48,6 @@ const char kNotePublicDtor[] =
const char kNoteProtectedNonVirtualDtor[] =
"[chromium-style] Protected non-virtual destructor declared here";
-bool TypeHasNonTrivialDtor(const Type* type) {
- if (const CXXRecordDecl* cxx_r = type->getAsCXXRecordDecl())
- return !cxx_r->hasTrivialDestructor();
-
- return false;
-}
-
// Returns the underlying Type for |type| by expanding typedefs and removing
// any namespace qualifiers. This is similar to desugaring, except that for
// ElaboratedTypes, desugar will unwrap too much.
@@ -564,12 +557,17 @@ void FindBadConstructsConsumer::CountType(const Type* type,
int* templated_non_trivial_member) {
switch (type->getTypeClass()) {
case Type::Record: {
+ auto* record_decl = type->getAsCXXRecordDecl();
// Simplifying; the whole class isn't trivial if the dtor is, but
// we use this as a signal about complexity.
- if (TypeHasNonTrivialDtor(type))
- (*non_trivial_member)++;
- else
+ // Note that if a record doesn't have a definition, it doesn't matter how
+ // it's counted, since the translation unit will fail to build. In that
+ // case, just count it as a trivial member to avoid emitting warnings that
+ // might be spurious.
+ if (!record_decl->hasDefinition() || record_decl->hasTrivialDestructor())
(*trivial_member)++;
+ else
+ (*non_trivial_member)++;
break;
}
case Type::TemplateSpecialization: {
« no previous file with comments | « no previous file | tools/clang/plugins/tests/class_with_incomplete_type.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698