diff --git a/llvm/unittests/Support/TrailingObjectsTest.cpp b/llvm/unittests/Support/TrailingObjectsTest.cpp index 6f9d7bda7fe5a..2590f375b6598 100644 --- a/llvm/unittests/Support/TrailingObjectsTest.cpp +++ b/llvm/unittests/Support/TrailingObjectsTest.cpp @@ -17,14 +17,12 @@ namespace { // This class, beyond being used by the test case, a nice // demonstration of the intended usage of TrailingObjects, with a // single trailing array. -class Class1 final : protected TrailingObjects { +class Class1 final : private TrailingObjects { friend TrailingObjects; unsigned NumShorts; protected: - size_t numTrailingObjects(OverloadToken) const { return NumShorts; } - Class1(ArrayRef ShortArray) : NumShorts(ShortArray.size()) { // This tests the non-templated getTrailingObjects() that returns a pointer // when using a single trailing type. @@ -52,18 +50,15 @@ class Class1 final : protected TrailingObjects { using TrailingObjects::getTrailingObjects; }; -// Here, there are two singular optional object types appended. Note +// Here, there are two singular optional object types appended. Note // that the alignment of Class2 is automatically increased to account // for the alignment requirements of the trailing objects. -class Class2 final : protected TrailingObjects { +class Class2 final : private TrailingObjects { friend TrailingObjects; bool HasShort, HasDouble; protected: - size_t numTrailingObjects(OverloadToken) const { - return HasShort ? 1 : 0; - } size_t numTrailingObjects(OverloadToken) const { return HasDouble ? 1 : 0; } @@ -179,14 +174,23 @@ TEST(TrailingObjects, TwoArg) { } // This test class is not trying to be a usage demo, just asserting -// that three args does actually work too (it's the same code as +// that three args does actually work too (it's the same code that // handles the second arg, so it's basically covered by the above, but // just in case..) -class Class3 final : public TrailingObjects { +class Class3 final : private TrailingObjects { friend TrailingObjects; size_t numTrailingObjects(OverloadToken) const { return 1; } size_t numTrailingObjects(OverloadToken) const { return 1; } + +public: + // Pull some protected members in as public, for testability. + template + using FixedSizeStorage = TrailingObjects::FixedSizeStorage; + + using TrailingObjects::additionalSizeToAlloc; + using TrailingObjects::getTrailingObjects; + using TrailingObjects::totalSizeToAlloc; }; TEST(TrailingObjects, ThreeArg) { @@ -216,9 +220,18 @@ TEST(TrailingObjects, ThreeArg) { 1)); } -class Class4 final : public TrailingObjects { +class Class4 final : private TrailingObjects { friend TrailingObjects; size_t numTrailingObjects(OverloadToken) const { return 1; } + +public: + // Pull some protected members in as public, for testability. + template + using FixedSizeStorage = TrailingObjects::FixedSizeStorage; + + using TrailingObjects::additionalSizeToAlloc; + using TrailingObjects::getTrailingObjects; + using TrailingObjects::totalSizeToAlloc; }; TEST(TrailingObjects, Realignment) { @@ -255,11 +268,6 @@ class Class5Tmpl : private llvm::TrailingObjects { typename TrailingObjects::template OverloadToken) const { return 1; } - - size_t numTrailingObjects( - typename TrailingObjects::template OverloadToken) const { - return 2; - } }; class Class5 : public Class5Tmpl {};