[clang-tidy] fix false-positive for cppcoreguidelines-pro-type-member-init with in-class initializers
Summary: This fixes https://llvm.org/bugs/show_bug.cgi?id=30487 where ``` warning: uninitialized record type: 's' [cppcoreguidelines-pro-type-member-init] ``` is emitted on ``` struct MyStruct { int a = 5; int b = 7; }; int main() { MyStruct s; } ``` Reviewers: alexfh, aaron.ballman Subscribers: nemanjai, cfe-commits Differential Revision: https://reviews.llvm.org/D24848 llvm-svn: 282625
This commit is contained in:
parent
e14df4b236
commit
6207d459a4
|
@ -62,8 +62,10 @@ bool recordIsTriviallyDefaultConstructible(const RecordDecl &RecordDecl,
|
|||
if (ClassDecl->hasTrivialDefaultConstructor())
|
||||
return true;
|
||||
|
||||
// If all its fields are trivially constructible.
|
||||
// If all its fields are trivially constructible and have no default initializers.
|
||||
for (const FieldDecl *Field : ClassDecl->fields()) {
|
||||
if (Field->hasInClassInitializer())
|
||||
return false;
|
||||
if (!isTriviallyDefaultConstructible(Field->getType(), Context))
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -73,6 +73,11 @@ struct NegativeInClassInitialized {
|
|||
NegativeInClassInitialized() {}
|
||||
};
|
||||
|
||||
struct NegativeInClassInitializedDefaulted {
|
||||
int F = 0;
|
||||
NegativeInClassInitializedDefaulted() = default;
|
||||
};
|
||||
|
||||
struct NegativeConstructorDelegated {
|
||||
int F;
|
||||
|
||||
|
@ -367,3 +372,8 @@ class PositiveIndirectMember {
|
|||
PositiveIndirectMember() {}
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: A
|
||||
};
|
||||
|
||||
void Bug30487()
|
||||
{
|
||||
NegativeInClassInitializedDefaulted s;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue