[PATCH] D42413: [clang-tidy] Handle bitfields in modernize-use-default-member-init if using C++2a

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 23 06:06:34 PST 2018


aaron.ballman added inline comments.


================
Comment at: clang-tidy/modernize/UseDefaultMemberInitCheck.cpp:165
 
-  Finder->addMatcher(
-      cxxConstructorDecl(
-          isDefaultConstructor(), unless(isInstantiated()),
-          forEachConstructorInitializer(
-              cxxCtorInitializer(
-                  forField(unless(anyOf(isBitField(),
-                                        hasInClassInitializer(anything()),
-                                        hasParent(recordDecl(isUnion()))))),
-                  isWritten(), withInitializer(ignoringImplicit(Init)))
-                  .bind("default"))),
-      this);
+  if (getLangOpts().CPlusPlus2a)
+    Finder->addMatcher(
----------------
I wonder if we could add a `nothing()` matcher (sibling to the `anything()` matcher) so that this could be rewritten as:

`unless(anyOf(getLangOpts().CPlusPlus2a ? nothing() : isBitField()))`

The duplication here adds complexity if we decide to change the matchers in the future.


================
Comment at: test/clang-tidy/modernize-use-default-member-init-bitfield.cpp:1
+// RUN: %check_clang_tidy %s modernize-use-default-member-init %t -- -- -std=c++2a
+
----------------
I'd like to see a test where C++2a is not enabled to ensure that the fix is not suggested in that case.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42413





More information about the cfe-commits mailing list