File tree Expand file tree Collapse file tree 3 files changed +23
-2
lines changed
test/Interop/Cxx/class/inheritance Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -460,8 +460,14 @@ namespace {
460460
461461 unsigned baseOffset = 0 ;
462462 if (auto cxxRecord = dyn_cast<clang::CXXRecordDecl>(ClangDecl)) {
463- baseOffset =
464- std::distance (cxxRecord->bases ().begin (), cxxRecord->bases ().end ());
463+ baseOffset = llvm::count_if (cxxRecord->bases (), [](auto base) {
464+ auto baseType = base.getType ().getCanonicalType ();
465+
466+ auto baseRecord = cast<clang::RecordType>(baseType)->getDecl ();
467+ auto baseCxxRecord = cast<clang::CXXRecordDecl>(baseRecord);
468+
469+ return !baseCxxRecord->isEmpty ();
470+ });
465471 }
466472
467473 // Otherwise, project from the base.
Original file line number Diff line number Diff line change @@ -49,3 +49,12 @@ struct DerivedFromDerived : Derived {
4949};
5050
5151struct DerivedFromNonTrivial : NonTrivial {};
52+
53+ struct EmptyBaseClass {
54+ const char *inBase () const { return " EmptyBaseClass::inBase" ; }
55+ };
56+
57+ struct DerivedFromEmptyBaseClass : EmptyBaseClass {
58+ int a = 42 ;
59+ int b = 42 ;
60+ };
Original file line number Diff line number Diff line change @@ -69,4 +69,10 @@ FunctionsTestSuite.test("base member from derived from non trivial") {
6969 expectEqual ( String ( cString: dnt. inNonTrivialWithArgs ( 0 , 1 ) !) , " NonTrivial::inNonTrivialWithArgs " )
7070}
7171
72+ FunctionsTestSuite . test ( " non-empty derived from empty class " ) {
73+ let derived = DerivedFromEmptyBaseClass ( )
74+ expectEqual ( String ( cString: derived. inBase ( ) !) , " EmptyBaseClass::inBase " )
75+ expectEqual ( derived. b, 42 )
76+ }
77+
7278runAllTests ( )
You can’t perform that action at this time.
0 commit comments