[PATCH] D100057: Remove warning "suggest braces" for aggregate initialization of an empty class with an aggregate base class.

JF Bastien via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 7 13:45:30 PDT 2021


jfb accepted this revision.
jfb added a comment.
This revision is now accepted and ready to land.

A few nits, but this is good otherwise!



================
Comment at: clang/lib/Sema/SemaInit.cpp:1013
 
-  auto *ParentRD =
-      Entity.getParent()->getType()->castAs<RecordType>()->getDecl();
-  if (CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(ParentRD))
-    if (CXXRD->getNumBases())
-      return false;
+  // Allows elide brace initialization for aggregates with empty base
+  if (Entity.getKind() == InitializedEntity::EK_Base) {
----------------
"Allow eliding brace initialization".

Also, period at the end of the sentence.



================
Comment at: clang/lib/Sema/SemaInit.cpp:1018
+    if (CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(ParentRD)) {
+      if (CXXRD->getNumBases() == 1) {
+        return ParentRD->field_begin() == ParentRD->field_end();
----------------
Multiple empty bases isn't a common thing, right? I don't think so, but would rather check.


================
Comment at: clang/lib/Sema/SemaInit.cpp:1025
 
-  auto FieldIt = ParentRD->field_begin();
-  assert(FieldIt != ParentRD->field_end() &&
-         "no fields but have initializer for member?");
-  return ++FieldIt == ParentRD->field_end();
+  // Allows elide brace initilization for aggregates with one member
+  if (Entity.getKind() == InitializedEntity::EK_Member) {
----------------
Same here.


================
Comment at: clang/test/SemaCXX/aggregate-initialization.cpp:183
+  OnionBaseClass<int, 3> u = {1, 2, 3};
+  OnionBaseClass<int, 3> t = {{{1, 2, 3}}};
+
----------------
Haha I like the name! 🧅😭


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100057/new/

https://reviews.llvm.org/D100057



More information about the cfe-commits mailing list