1212using namespace llvm ;
1313
1414namespace {
15- // This class, beyond being used by the test case, a nice
16- // demonstration of the intended usage of TrailingObjects, with a
17- // single trailing array.
18- class Class1 final : protected TrailingObjects<Class1, short > {
15+ // This class, beyond being used by the test case, a nice demonstration of the
16+ // intended usage of TrailingObjects, with a single trailing array.
17+ class Class1 final : private TrailingObjects<Class1, short > {
1918 friend TrailingObjects;
2019
2120 unsigned NumShorts;
2221
2322protected:
24- size_t numTrailingObjects (OverloadToken<short >) const { return NumShorts; }
25-
2623 Class1 (int *ShortArray, unsigned NumShorts) : NumShorts(NumShorts) {
24+ // This tests the non-templated getTrailingObjects() when using a single
25+ // trailing type.
2726 std::uninitialized_copy (ShortArray, ShortArray + NumShorts,
28- getTrailingObjects<short >());
27+ getTrailingObjects ());
28+
29+ EXPECT_EQ (getTrailingObjects (), getTrailingObjects<short >());
2930 }
3031
3132public:
3233 static Class1 *create (int *ShortArray, unsigned NumShorts) {
3334 void *Mem = ::operator new (totalSizeToAlloc<short >(NumShorts));
3435 return new (Mem) Class1 (ShortArray, NumShorts);
3536 }
36- void operator delete (void *p ) { ::operator delete (p ); }
37+ void operator delete (void *Ptr ) { ::operator delete (Ptr ); }
3738
38- short get (unsigned Num) const { return getTrailingObjects<short >()[Num]; }
39+ // This indexes into the ArrayRef<> returned by `getTrailingObjects`.
40+ short get (unsigned Num) const { return getTrailingObjects (NumShorts)[Num]; }
3941
4042 unsigned numShorts () const { return NumShorts; }
4143
@@ -48,9 +50,9 @@ class Class1 final : protected TrailingObjects<Class1, short> {
4850 using TrailingObjects::getTrailingObjects;
4951};
5052
51- // Here, there are two singular optional object types appended. Note
52- // that the alignment of Class2 is automatically increased to account
53- // for the alignment requirements of the trailing objects.
53+ // Here, there are two singular optional object types appended. Note that the
54+ // alignment of Class2 is automatically increased to account for the alignment
55+ // requirements of the trailing objects.
5456class Class2 final : protected TrailingObjects<Class2, double , short > {
5557 friend TrailingObjects;
5658
@@ -81,7 +83,7 @@ class Class2 final : protected TrailingObjects<Class2, double, short> {
8183 *C->getTrailingObjects <double >() = D;
8284 return C;
8385 }
84- void operator delete (void *p ) { ::operator delete (p ); }
86+ void operator delete (void *Ptr ) { ::operator delete (Ptr ); }
8587
8688 short getShort () const {
8789 if (!HasShort)
@@ -171,10 +173,9 @@ TEST(TrailingObjects, TwoArg) {
171173 delete C2;
172174}
173175
174- // This test class is not trying to be a usage demo, just asserting
175- // that three args does actually work too (it's the same code as
176- // handles the second arg, so it's basically covered by the above, but
177- // just in case..)
176+ // This test class is not trying to be a usage demo, just asserting that three
177+ // args does actually work too (it's the same code as handles the second arg, so
178+ // it's basically covered by the above, but just in case..)
178179class Class3 final : public TrailingObjects<Class3, double , short , bool > {
179180 friend TrailingObjects;
180181
@@ -236,9 +237,9 @@ TEST(TrailingObjects, Realignment) {
236237}
237238}
238239
239- // Test the use of TrailingObjects with a template class. This
240- // previously failed to compile due to a bug in MSVC's member access
241- // control/lookup handling for OverloadToken.
240+ // Test the use of TrailingObjects with a template class. This previously failed
241+ // to compile due to a bug in MSVC's member access control/lookup handling for
242+ // OverloadToken.
242243template <typename Derived>
243244class Class5Tmpl : private llvm ::TrailingObjects<Derived, float , int > {
244245 using TrailingObjects = typename llvm::TrailingObjects<Derived, float >;
0 commit comments