From: Malcolm Parsons Date: Tue, 23 Jan 2018 15:32:42 +0000 (+0000) Subject: [clang-tidy] Handle bitfields in modernize-use-default-member-init if using C++2a X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e034e5eefe84665fdcd53ef6df521ddc2e3ecca3;p=platform%2Fupstream%2Fllvm.git [clang-tidy] Handle bitfields in modernize-use-default-member-init if using C++2a Summary: C++2a allows bitfields to have default member initializers. Add support for this to clang-tidy's modernize-use-default-member-init check. Reviewers: aaron.ballman, alexfh Reviewed By: aaron.ballman Subscribers: klimek, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D42413 llvm-svn: 323208 --- diff --git a/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp index b07f730..c14c685 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp @@ -167,7 +167,9 @@ void UseDefaultMemberInitCheck::registerMatchers(MatchFinder *Finder) { isDefaultConstructor(), unless(isInstantiated()), forEachConstructorInitializer( cxxCtorInitializer( - forField(unless(anyOf(isBitField(), + forField(unless(anyOf(getLangOpts().CPlusPlus2a + ? unless(anything()) + : isBitField(), hasInClassInitializer(anything()), hasParent(recordDecl(isUnion()))))), isWritten(), withInitializer(ignoringImplicit(Init))) diff --git a/clang-tools-extra/test/clang-tidy/modernize-use-default-member-init-bitfield.cpp b/clang-tools-extra/test/clang-tidy/modernize-use-default-member-init-bitfield.cpp new file mode 100644 index 0000000..1ff08f9 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/modernize-use-default-member-init-bitfield.cpp @@ -0,0 +1,10 @@ +// RUN: %check_clang_tidy %s modernize-use-default-member-init %t -- -- -std=c++2a + +struct PositiveBitField +{ + PositiveBitField() : i(6) {} + // CHECK-FIXES: PositiveBitField() {} + int i : 5; + // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'i' [modernize-use-default-member-init] + // CHECK-FIXES: int i : 5{6}; +};