[Development] Qt Coding style and C++11

Kevin Funk kfunk at kde.org
Wed Nov 15 17:39:18 CET 2017


On Monday, 18 September 2017 10:03:40 CET Kevin Funk wrote:
> On Monday, 18 September 2017 09:38:53 CEST Ville Voutilainen wrote:
> > On 18 September 2017 at 10:36, Lars Knoll <lars.knoll at qt.io> wrote:
> > >>> But for new plugins that target a known platform that supports c++11,
> > >>> they can most likely use new conventions. Unless someone can come up
> > >>> with technical reasons the new c++11 member initialization is better
> > >>> than what is there now, I’d rather keep it the same as it is now.>>
> > >> 
> > >> If you have more than one constructor that set a member to the same
> > >> value, it's arguably simpler and less error-prone
> > >> to use a member initializer.
> > > 
> > > I also think that we should be using member initialisers when writing
> > > new
> > > code (or when refactoring existing code). But doing a global
> > > search/replace of existing code might lead to subtle errors as it's easy
> > > to miss the rare case when different constructors initialise members
> > > differently.
> > 
> > Note that if you have both a member initializer and a ctor-initializer
> > (the colon-list after the constructor signature, X() : foo(a),
> > bar(b)), the ctor-initializer
> > is used. It is non-trivial to remove ctor-initializers and replace
> > them with member-initializers, I don't know whether the clang-tools
> > can do that.
> 
> I have to take back my claim that clang-tidy can automatically transform
> initialization via initializer list to initialization via in-class field
> initializers.
> 
> I just remembered that this cppcoreguidelines-pro-type-member-init checker
> just *adds* in-class field initializers for fields which haven't been
> initialized altogether *before*. It does nothing if the initializer list
> initializes all fields already. So in order to actually port all uses of
> initializer lists to something more modern, clang-tidy would need to be
> extended.
> 
> So I guess the discussion whether to a global search/replace for this
> particular C++11 feature is moot for now, since doing this port on all of Qt
> is infeasible without proper tooling.

Heya,

And I have to revive this thread again. 

Actually the clang-tidy check to do this kind of transformation indeed exists 
already (since Clang 5.0 release):
  https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-default-member-init.html

Just for your information. 

Regards,
Kevin
 
> Regards,
> Kevin
> 
>  _______________________________________________
> 
> > Development mailing list
> > Development at qt-project.org
> > http://lists.qt-project.org/mailman/listinfo/development


-- 
Kevin Funk | kfunk at kde.org | http://kfunk.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 163 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/development/attachments/20171115/1bafdf25/attachment.sig>


More information about the Development mailing list