[PATCH] D12839: Extend MoveConstructorInitCheck to also flag constructor arguments passed by value and can be moved assigned to fields.
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 1 14:46:02 PDT 2016
aaron.ballman added a comment.
In https://reviews.llvm.org/D12839#582828, @malcolm.parsons wrote:
> The modernize-pass-by-value check does the same thing:
>
> test/clang-tidy/misc-move-constructor-init.cpp:98:12: warning: pass by value and use std::move [modernize-pass-by-value]
> Positive(Movable M) : M_(M) {}
> ^
> std::move( )
> test/clang-tidy/misc-move-constructor-init.cpp:98:28: warning: value argument 'M' can be moved to avoid copy [misc-move-constructor-init]
> Positive(Movable M) : M_(M) {}
> ^
>
>
> Do we need two checks for this?
This overlap is unfortunate. misc-move-constructor-init is for move constructor initializer lists which accidentally initialize a member or base through a copy constructor rather than a move constructor. Consider:
struct B { B(B&&); B(const B&); };
struct D {
D(D &&d) : B(d) {} // Oops, calling B(const B&) not B(B&&)
D(const D &d) : B(d) {}
modernize-pass-by-value is slightly different in that it is concerned with the parameter of an arbitrary function being something that is movable if you pass it by value instead of passing it by reference.
So misc-move-constructor-init cares about move constructor initializer lists while modernize-pass-by-value cares about the parameters of a function.
https://reviews.llvm.org/D12839
More information about the cfe-commits
mailing list