[PATCH] D16552: Implement the likely resolution of core issue 253.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 18 15:25:50 PST 2016


rsmith added inline comments.

================
Comment at: lib/AST/DeclCXX.cpp:396-425
@@ -394,1 +395,32 @@
 
+bool CXXRecordDecl::allowConstDefaultInitSlow() const {
+  assert(getDefinition() && "only call this on completed records");
+  if (hasUserProvidedDefaultConstructor()) {
+    data().setAllowConstDefInitKind(DefinitionData::ACDI_Yes);
+    return true;
+  }
+  for (const auto *F : fields()) {
+    if (F->hasInClassInitializer() || F->isMutable() || F->isUnnamedBitfield())
+      continue;
+    if (CXXRecordDecl *FieldType = F->getType()->getAsCXXRecordDecl()) {
+      if (!FieldType->allowConstDefaultInit()) {
+        data().setAllowConstDefInitKind(DefinitionData::ACDI_No);
+        return false;
+      }
+    } else {
+      data().setAllowConstDefInitKind(DefinitionData::ACDI_No);
+      return false;
+    }
+  }
+  for (const auto& BI : bases()) {
+    const RecordType *RT = BI.getType()->getAs<RecordType>();
+    CXXRecordDecl *Base = cast<CXXRecordDecl>(RT->getDecl());
+    if (!Base->allowConstDefaultInit()) {
+      data().setAllowConstDefInitKind(DefinitionData::ACDI_No);
+      return false;
+    }
+  }
+  data().setAllowConstDefInitKind(DefinitionData::ACDI_Yes);
+  return true;
+}
+
----------------
I don't expect this to be a measurable cost either way. I would strongly prefer to use the same pattern for all of these flags unless we have a really good reason not to.

================
Comment at: lib/Serialization/ASTReaderDecl.cpp:1517-1562
@@ -1515,48 +1516,48 @@
 
   // FIXME: Move this out into a .def file?
   bool DetectedOdrViolation = false;
 #define OR_FIELD(Field) DD.Field |= MergeDD.Field;
 #define MATCH_FIELD(Field) \
     DetectedOdrViolation |= DD.Field != MergeDD.Field; \
     OR_FIELD(Field)
   MATCH_FIELD(UserDeclaredConstructor)
   MATCH_FIELD(UserDeclaredSpecialMembers)
   MATCH_FIELD(Aggregate)
   MATCH_FIELD(PlainOldData)
   MATCH_FIELD(Empty)
   MATCH_FIELD(Polymorphic)
   MATCH_FIELD(Abstract)
   MATCH_FIELD(IsStandardLayout)
   MATCH_FIELD(HasNoNonEmptyBases)
   MATCH_FIELD(HasPrivateFields)
   MATCH_FIELD(HasProtectedFields)
   MATCH_FIELD(HasPublicFields)
   MATCH_FIELD(HasMutableFields)
   MATCH_FIELD(HasVariantMembers)
   MATCH_FIELD(HasOnlyCMembers)
   MATCH_FIELD(HasInClassInitializer)
   MATCH_FIELD(HasUninitializedReferenceMember)
   MATCH_FIELD(NeedOverloadResolutionForMoveConstructor)
   MATCH_FIELD(NeedOverloadResolutionForMoveAssignment)
   MATCH_FIELD(NeedOverloadResolutionForDestructor)
   MATCH_FIELD(DefaultedMoveConstructorIsDeleted)
   MATCH_FIELD(DefaultedMoveAssignmentIsDeleted)
   MATCH_FIELD(DefaultedDestructorIsDeleted)
   OR_FIELD(HasTrivialSpecialMembers)
   OR_FIELD(DeclaredNonTrivialSpecialMembers)
   MATCH_FIELD(HasIrrelevantDestructor)
   OR_FIELD(HasConstexprNonCopyMoveConstructor)
   MATCH_FIELD(DefaultedDefaultConstructorIsConstexpr)
   OR_FIELD(HasConstexprDefaultConstructor)
   MATCH_FIELD(HasNonLiteralTypeFieldsOrBases)
   // ComputedVisibleConversions is handled below.
   MATCH_FIELD(UserProvidedDefaultConstructor)
   OR_FIELD(DeclaredSpecialMembers)
   MATCH_FIELD(ImplicitCopyConstructorHasConstParam)
   MATCH_FIELD(ImplicitCopyAssignmentHasConstParam)
   OR_FIELD(HasDeclaredCopyConstructorWithConstParam)
   OR_FIELD(HasDeclaredCopyAssignmentWithConstParam)
   MATCH_FIELD(IsLambda)
 #undef OR_FIELD
 #undef MATCH_FIELD
 
----------------
You should update this block too.

================
Comment at: test/CXX/drs/dr4xx.cpp:1200
@@ -1199,3 +1199,3 @@
 
-namespace dr497 { // dr497: yes
+namespace dr497 { // dr497: no, superseded by dr253
   void before() {
----------------
Write this as "dr497: sup 253", and rerun www/make_cxx_dr_status to generate a new www/cxx_dr_status.html file. (You'll need to grab a cwg_index.html from the WG21 website.)


http://reviews.llvm.org/D16552





More information about the cfe-commits mailing list