forked from OSchip/llvm-project
[clang-tidy] Handle bitfields in cppcoreguidelines-pro-type-member-init
Summary: Unnamed bitfields cannot be initialized. Bitfields cannot be in-class initialized. Reviewers: alexfh, hokein, aaron.ballman Subscribers: Prazek, nemanjai, cfe-commits Differential Revision: https://reviews.llvm.org/D26119 llvm-svn: 285752
This commit is contained in:
parent
5fc84a1828
commit
883ebacd78
|
@ -358,7 +358,7 @@ void ProTypeMemberInitCheck::checkMissingMemberInitializer(
|
|||
if (!F->hasInClassInitializer() &&
|
||||
utils::type_traits::isTriviallyDefaultConstructible(F->getType(),
|
||||
Context) &&
|
||||
!isEmpty(Context, F->getType()))
|
||||
!isEmpty(Context, F->getType()) && !F->isUnnamedBitfield())
|
||||
FieldsToInit.insert(F);
|
||||
});
|
||||
if (FieldsToInit.empty())
|
||||
|
@ -407,7 +407,9 @@ void ProTypeMemberInitCheck::checkMissingMemberInitializer(
|
|||
SmallPtrSet<const FieldDecl *, 16> FieldsToFix;
|
||||
forEachField(ClassDecl, FieldsToInit, true, [&](const FieldDecl *F) {
|
||||
// Don't suggest fixes for enums because we don't know a good default.
|
||||
if (!F->getType()->isEnumeralType())
|
||||
// Don't suggest fixes for bitfields because in-class initialization is not
|
||||
// possible.
|
||||
if (!F->getType()->isEnumeralType() && !F->isBitField())
|
||||
FieldsToFix.insert(F);
|
||||
});
|
||||
if (FieldsToFix.empty())
|
||||
|
|
|
@ -456,3 +456,20 @@ template <typename T> class NoCrash {
|
|||
template <typename U> B(U u) {}
|
||||
};
|
||||
};
|
||||
|
||||
struct PositiveBitfieldMember {
|
||||
PositiveBitfieldMember() {}
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: F
|
||||
unsigned F : 5;
|
||||
};
|
||||
|
||||
struct NegativeUnnamedBitfieldMember {
|
||||
NegativeUnnamedBitfieldMember() {}
|
||||
unsigned : 5;
|
||||
};
|
||||
|
||||
struct NegativeInitializedBitfieldMembers {
|
||||
NegativeInitializedBitfieldMembers() : F(3) { G = 2; }
|
||||
unsigned F : 5;
|
||||
unsigned G : 5;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue