[PATCH] D125402: [clang][diag] warn if function returns class type by-const-value
Erich Keane via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 2 10:35:16 PDT 2022
erichkeane added a comment.
In D125402#3553802 <https://reviews.llvm.org/D125402#3553802>, @aaron.ballman wrote:
> In D125402#3517865 <https://reviews.llvm.org/D125402#3517865>, @nlee wrote:
>
>> How about adding CXXRecordDecl::hasMoveConstructor() to ensure the type is movable? I ran a test with OpenCV(c++11), and it returned some useful warnings:
>
> I don't think that will be quite correct -- IIRC, that would still return true if the move constructor was deleted. `hasSimpleMoveConstructor()` and `hasSimpleMoveAssignment()` might be a better approach.
The 'Simple' version might not be quite right... That is implemented as:
bool hasSimpleMoveConstructor() const {
return !hasUserDeclaredMoveConstructor() && hasMoveConstructor() &&
!data().DefaultedMoveConstructorIsDeleted;
}
So this would still warn about user-defined move constructors.
HOWEVER, I might suggest `hasMoveConstructor() && !defaultedMoveConstructorIsDeleted()` for the ctor test. There is similar storage for the 'DefaultedMoveAssignmentIsDeleted`, but it isn't exposed, so you might need to add a function to expose it in DeclCXX.h.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D125402/new/
https://reviews.llvm.org/D125402
More information about the cfe-commits
mailing list