This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Handle unions in modernize-use-equals-default check
Needs RevisionPublic

Authored by malcolm.parsons on Sep 22 2017, 8:48 AM.

Details

Summary

Do not replace the constructor or destructor of a union with =default
if it would be implicitly deleted.

Fixes: PR27926

Event Timeline

aaron.ballman added inline comments.Sep 24 2017, 8:13 AM
clang-tidy/modernize/UseEqualsDefaultCheck.cpp
117

Please don't use auto here or elsewhere if the type is not explicitly spelled out.

119–120

This does not match what's in [class.ctor]p5.

"X is a union that has a variant member with a non-trivial default constructor and no variant member of X has a default member initializer" -- you aren't checking for the default member initializer.

also missing for unions: "X is a union and all of its variant members are of const-qualified type (or array thereof)"

(You should add test cases for these.)

It might make more sense to implement this as CXXRecordDecl::defaultedDestructorIsDeleted()?

127

You can use auto here and below.

clang-tidy/modernize/UseEqualsDefaultCheck.cpp
117

This was copied from isCopyAssignmentAndCanBeDefaulted().

119–120

Is there any way to call Sema::ShouldDeleteSpecialMember() from a clang-tidy check?

127

This was copied from CXXRecordDecl::addedMember().

alexfh added inline comments.Sep 27 2017, 6:45 AM
clang-tidy/modernize/UseEqualsDefaultCheck.cpp
119–120

By the time clang-tidy checks are invoked, Sema is already dead, and I don't think there's a reasonable way to use it.

127

Not all LLVM/Clang code is ideal. It makes sense to clean up issues once the code is changed and even more so when it's copied elsewhere.

alexfh requested changes to this revision.Mar 14 2018, 7:53 AM
This revision now requires changes to proceed.Mar 14 2018, 7:53 AM