[PATCH] D42426: [clang-tidy] Handle bitfields in cppcoreguidelines-pro-type-member-init if using C++2a
Malcolm Parsons via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 23 08:44:02 PST 2018
malcolm.parsons created this revision.
malcolm.parsons added reviewers: aaron.ballman, alexfh.
Herald added subscribers: cfe-commits, kbarton, xazax.hun, nemanjai, klimek.
C++2a allows bitfields to have default member initializers.
Add support for this to clang-tidy's cppcoreguidelines-pro-type-member-init check.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D42426
Files:
clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
test/clang-tidy/cppcoreguidelines-pro-type-member-init-cxx2a.cpp
test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
Index: test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
===================================================================
--- test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
+++ test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
@@ -474,6 +474,7 @@
PositiveBitfieldMember() {}
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: F
unsigned F : 5;
+ // CHECK-FIXES-NOT: unsigned F : 5{};
};
struct NegativeUnnamedBitfieldMember {
Index: test/clang-tidy/cppcoreguidelines-pro-type-member-init-cxx2a.cpp
===================================================================
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-pro-type-member-init-cxx2a.cpp
@@ -0,0 +1,19 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-member-init %t -- -- -std=c++2a -fno-delayed-template-parsing
+
+struct PositiveBitfieldMember {
+ PositiveBitfieldMember() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: F
+ unsigned F : 5;
+ // CHECK-FIXES: unsigned F : 5{};
+};
+
+struct NegativeUnnamedBitfieldMember {
+ NegativeUnnamedBitfieldMember() {}
+ unsigned : 5;
+};
+
+struct NegativeInitializedBitfieldMembers {
+ NegativeInitializedBitfieldMembers() : F(3) { G = 2; }
+ unsigned F : 5;
+ unsigned G : 5;
+};
Index: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===================================================================
--- clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -404,8 +404,9 @@
return;
// Don't suggest fixes for enums because we don't know a good default.
// Don't suggest fixes for bitfields because in-class initialization is not
- // possible.
- if (F->getType()->isEnumeralType() || F->isBitField())
+ // possible until C++2a.
+ if (F->getType()->isEnumeralType() ||
+ (!getLangOpts().CPlusPlus2a && F->isBitField()))
return;
if (!F->getParent()->isUnion() || UnionsSeen.insert(F->getParent()).second)
FieldsToFix.insert(F);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42426.131088.patch
Type: text/x-patch
Size: 2118 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180123/f706c484/attachment.bin>
More information about the cfe-commits
mailing list