[PATCH] D28287: [clang-tidy] Ignore default arguments in modernize-default-member-init

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 4 09:34:11 PST 2017


aaron.ballman added inline comments.


================
Comment at: clang-tidy/modernize/UseDefaultMemberInitCheck.cpp:161
             cxxBoolLiteral(), cxxNullPtrLiteralExpr(), implicitValueInitExpr(),
-            declRefExpr());
+            declRefExpr(unless(to(varDecl()))));
 
----------------
malcolm.parsons wrote:
> aaron.ballman wrote:
> > malcolm.parsons wrote:
> > > aaron.ballman wrote:
> > > > Any `varDecl`? Or do we want to limit it to only `parmVarDecl` instead?
> > > > ```
> > > > int i = 12;
> > > > struct S {
> > > >   int j;
> > > >   S() : j(i) {}
> > > > };
> > > > ```
> > > > It seems reasonable to suggest the member initialization be "fixed" to: `int j = i;`
> > > I would find a default member initializer that is not a constant to be surprising.
> > > Maybe I want to limit it to `enumConstantDecl`.
> > I wouldn't; consider a global synchronization object, like a mutex (this is a relatively common thing).
> Note that this check doesn't consider initializations of members that are classes, e.g. `std::lock_guard`.
> I have no plans to make it consider them.
Ah, okay, then it's less pressing, though the pattern is still not unheard of for non-class types. I don't have a strong opinion any longer, though.


================
Comment at: test/clang-tidy/modernize-use-default-member-init.cpp:224
 
+struct NegativeDefaultArg
+{
----------------
Can we also have a positive test with an enumerator?


https://reviews.llvm.org/D28287





More information about the cfe-commits mailing list