12
12
using namespace llvm ;
13
13
14
14
namespace {
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 > {
19
18
friend TrailingObjects;
20
19
21
20
unsigned NumShorts;
22
21
23
22
protected:
24
- size_t numTrailingObjects (OverloadToken<short >) const { return NumShorts; }
25
-
26
23
Class1 (int *ShortArray, unsigned NumShorts) : NumShorts(NumShorts) {
24
+ // This tests the non-templated getTrailingObjects() when using a single
25
+ // trailing type.
27
26
std::uninitialized_copy (ShortArray, ShortArray + NumShorts,
28
- getTrailingObjects<short >());
27
+ getTrailingObjects ());
28
+
29
+ EXPECT_EQ (getTrailingObjects (), getTrailingObjects<short >());
29
30
}
30
31
31
32
public:
32
33
static Class1 *create (int *ShortArray, unsigned NumShorts) {
33
34
void *Mem = ::operator new (totalSizeToAlloc<short >(NumShorts));
34
35
return new (Mem) Class1 (ShortArray, NumShorts);
35
36
}
36
- void operator delete (void *p ) { ::operator delete (p ); }
37
+ void operator delete (void *Ptr ) { ::operator delete (Ptr ); }
37
38
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]; }
39
41
40
42
unsigned numShorts () const { return NumShorts; }
41
43
@@ -48,9 +50,9 @@ class Class1 final : protected TrailingObjects<Class1, short> {
48
50
using TrailingObjects::getTrailingObjects;
49
51
};
50
52
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.
54
56
class Class2 final : protected TrailingObjects<Class2, double , short > {
55
57
friend TrailingObjects;
56
58
@@ -81,7 +83,7 @@ class Class2 final : protected TrailingObjects<Class2, double, short> {
81
83
*C->getTrailingObjects <double >() = D;
82
84
return C;
83
85
}
84
- void operator delete (void *p ) { ::operator delete (p ); }
86
+ void operator delete (void *Ptr ) { ::operator delete (Ptr ); }
85
87
86
88
short getShort () const {
87
89
if (!HasShort)
@@ -171,10 +173,9 @@ TEST(TrailingObjects, TwoArg) {
171
173
delete C2;
172
174
}
173
175
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..)
178
179
class Class3 final : public TrailingObjects<Class3, double , short , bool > {
179
180
friend TrailingObjects;
180
181
@@ -236,9 +237,9 @@ TEST(TrailingObjects, Realignment) {
236
237
}
237
238
}
238
239
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.
242
243
template <typename Derived>
243
244
class Class5Tmpl : private llvm ::TrailingObjects<Derived, float , int > {
244
245
using TrailingObjects = typename llvm::TrailingObjects<Derived, float >;
0 commit comments