[PATCH] D26119: [clang-tidy] Handle bitfields in cppcoreguidelines-pro-type-member-init
Malcolm Parsons via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 1 14:36:25 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285752: [clang-tidy] Handle bitfields in cppcoreguidelines-pro-type-member-init (authored by malcolm.parsons).
Changed prior to commit:
https://reviews.llvm.org/D26119?vs=76313&id=76635#toc
Repository:
rL LLVM
https://reviews.llvm.org/D26119
Files:
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
Index: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
@@ -456,3 +456,20 @@
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;
+};
Index: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -358,7 +358,7 @@
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 @@
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())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26119.76635.patch
Type: text/x-patch
Size: 2029 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161101/2ba6baaa/attachment.bin>
More information about the cfe-commits
mailing list