[PATCH] D38179: [clang-tidy] Handle unions in modernize-use-equals-default check

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 25 05:04:40 PDT 2017

aaron.ballman added inline comments.

Comment at: clang-tidy/modernize/UseEqualsDefaultCheck.cpp:117
+                                             const CXXMethodDecl *Operator) {
+  const auto *Record = Operator->getParent();
Please don't use `auto` here or elsewhere if the type is not explicitly spelled out.

Comment at: clang-tidy/modernize/UseEqualsDefaultCheck.cpp:119-120
+  // A defaulted default constructor of a union with a field with a non trivial
+  // default constructor would be deleted.
+  if (Record->isUnion()) {
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()`?

Comment at: clang-tidy/modernize/UseEqualsDefaultCheck.cpp:127
+      if (const RecordType *RecordTy = T->getAs<RecordType>()) {
+        CXXRecordDecl *FieldRec = cast<CXXRecordDecl>(RecordTy->getDecl());
You can use `auto` here and below.


More information about the cfe-commits mailing list