aboutsummaryrefslogtreecommitdiff
path: root/clang-tidy/utils
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2016-10-04 14:48:05 +0000
committerAaron Ballman <aaron@aaronballman.com>2016-10-04 14:48:05 +0000
commit43a0574f3c9829574f1b33f5869e70701eca2afc (patch)
tree6f6e088ffffa6e3a03a928b779792892860413d9 /clang-tidy/utils
parentee36f5c64f1ff60d9aef4b97ae777ebe5222263c (diff)
Fix some false-positives with cppcoreguidelines-pro-type-member-init. Handle classes with default constructors that are defaulted or are not present in the AST.
Classes with virtual methods or virtual bases are not trivially default constructible, so their members and bases need to be initialized. Patch by Malcolm Parsons. git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@283224 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'clang-tidy/utils')
-rw-r--r--clang-tidy/utils/TypeTraits.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/clang-tidy/utils/TypeTraits.cpp b/clang-tidy/utils/TypeTraits.cpp
index a0e40fe7..03b05d19 100644
--- a/clang-tidy/utils/TypeTraits.cpp
+++ b/clang-tidy/utils/TypeTraits.cpp
@@ -58,6 +58,9 @@ bool recordIsTriviallyDefaultConstructible(const RecordDecl &RecordDecl,
// constructible.
if (ClassDecl->hasUserProvidedDefaultConstructor())
return false;
+ // A polymorphic class is not trivially constructible
+ if (ClassDecl->isPolymorphic())
+ return false;
// A class is trivially constructible if it has a trivial default constructor.
if (ClassDecl->hasTrivialDefaultConstructor())
return true;
@@ -73,6 +76,8 @@ bool recordIsTriviallyDefaultConstructible(const RecordDecl &RecordDecl,
for (const CXXBaseSpecifier &Base : ClassDecl->bases()) {
if (!isTriviallyDefaultConstructible(Base.getType(), Context))
return false;
+ if (Base.isVirtual())
+ return false;
}
return true;