[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 07:30:16 PST 2018


aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!



================
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(
----------------
malcolm.parsons wrote:
> aaron.ballman wrote:
> > 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.
> `unless(anything())` is equivalent to `nothing()`.
Ah, good point! Nice, this is much more clean.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42413





More information about the cfe-commits mailing list