diff options
Diffstat (limited to 'clang/lib/Sema/SemaInit.cpp')
-rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index ec7e472..c8e8c86 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -1007,21 +1007,33 @@ static bool isIdiomaticBraceElisionEntity(const InitializedEntity &Entity) { // // (where std::array is an aggregate struct containing a single array field. - // FIXME: Should aggregate initialization of a struct with a single - // base class and no members also suppress the warning? - if (Entity.getKind() != InitializedEntity::EK_Member || !Entity.getParent()) + if (!Entity.getParent()) return false; - 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) { + auto *ParentRD = + Entity.getParent()->getType()->castAs<RecordType>()->getDecl(); + CXXRecordDecl *CXXRD = cast<CXXRecordDecl>(ParentRD); + return CXXRD->getNumBases() == 1 && CXXRD->field_empty(); + } + + // Allow brace elision if the only subobject is a field. + if (Entity.getKind() == InitializedEntity::EK_Member) { + auto *ParentRD = + Entity.getParent()->getType()->castAs<RecordType>()->getDecl(); + if (CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(ParentRD)) { + if (CXXRD->getNumBases()) { + return false; + } + } + auto FieldIt = ParentRD->field_begin(); + assert(FieldIt != ParentRD->field_end() && + "no fields but have initializer for member?"); + return ++FieldIt == ParentRD->field_end(); + } - auto FieldIt = ParentRD->field_begin(); - assert(FieldIt != ParentRD->field_end() && - "no fields but have initializer for member?"); - return ++FieldIt == ParentRD->field_end(); + return false; } /// Check whether the range of the initializer \p ParentIList from element |