Index: clang/lib/StaticAnalyzer/Core/RegionStore.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/RegionStore.cpp +++ clang/lib/StaticAnalyzer/Core/RegionStore.cpp @@ -2337,9 +2337,37 @@ const nonloc::CompoundVal& CV = V.castAs(); nonloc::CompoundVal::iterator VI = CV.begin(), VE = CV.end(); - RecordDecl::field_iterator FI, FE; RegionBindingsRef NewB(B); + // In C++17 aggregates may have base classes, handle those as well. + // They appear before fields in the initializer list / compound value. + if (const auto *CRD = dyn_cast(RD)) { + assert(CRD->isAggregate()); + + // Virtual bases still aren't allowed. Multiple bases are fine though. + for (auto B : CRD->bases()) { + assert(B.isVirtual() == false); + + if (VI == VE) + break; + + QualType BTy = B.getType(); + assert(BTy->isStructureOrClassType()); + + const CXXRecordDecl *BRD = BTy->getAsCXXRecordDecl(); + assert(BRD); + + const CXXBaseObjectRegion *BR = + MRMgr.getCXXBaseObjectRegion(BRD, R, /*IsVirtual=*/false); + + NewB = bindStruct(NewB, BR, *VI); + + ++VI; + } + } + + RecordDecl::field_iterator FI, FE; + for (FI = RD->field_begin(), FE = RD->field_end(); FI != FE; ++FI) { if (VI == VE) Index: clang/test/Analysis/array-struct-region.cpp =================================================================== --- clang/test/Analysis/array-struct-region.cpp +++ clang/test/Analysis/array-struct-region.cpp @@ -1,7 +1,9 @@ // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core,debug.ExprInspection -verify -x c %s // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core,debug.ExprInspection -verify -x c++ -analyzer-config c++-inlining=constructors %s +// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core,debug.ExprInspection -verify -x c++ -std=c++17 -analyzer-config c++-inlining=constructors %s // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core,debug.ExprInspection -DINLINE -verify -x c %s // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core,debug.ExprInspection -DINLINE -verify -x c++ -analyzer-config c++-inlining=constructors %s +// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core,debug.ExprInspection -DINLINE -verify -x c++ -std=c++17 -analyzer-config c++-inlining=constructors %s void clang_analyzer_eval(int); @@ -196,4 +198,21 @@ } } +namespace flex_array_inheritance_cxx17 { +struct A { + int flexible_array[]; +}; + +struct B { + long cookie; +}; + +struct C : B { + A a; +}; + +void k() { + C c{}; +} +} // namespace flex_array_inheritance_cxx17 #endif