]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/allocator/64135.cc
1 // { dg-do compile { target std_allocator_new } }
2 // { dg-add-options no_pch }
3 // { dg-require-effective-target hosted }
7 #define new_allocator 1
8 #define malloc_allocator 1
9 #define bitmap_allocator 1
12 #if __cplusplus >= 201103L
13 #define STATIC_ASSERT(X) static_assert((X), #X)
15 #define PASTE2(X, Y) X##Y
16 #define PASTE(X, Y) PASTE2(X, Y)
17 #define STATIC_ASSERT(X) char PASTE(_assertion_, __LINE__) [(X) ? 1 : -1]
21 #undef malloc_allocator
22 #include <ext/new_allocator.h>
23 #include <ext/malloc_allocator.h>
25 struct N
: __gnu_cxx::new_allocator
<char> { };
27 struct A
: std::allocator
<char>, N
{ };
28 struct B
: std::allocator
<char> { N n
; };
30 // Verify that layout was not changed by removing std::allocator inheritance
31 // from __gnu_cxx::new_allocator:
32 STATIC_ASSERT( sizeof(A
) == 2 );
33 STATIC_ASSERT( sizeof(B
) == 2 );
35 struct M
: __gnu_cxx::malloc_allocator
<char> { };
38 // Verify that malloc_allocator can be an overlapping subobject with
40 STATIC_ASSERT( sizeof(M
) == 1 );
41 STATIC_ASSERT( sizeof(C
) == 1 );
43 struct D
: std::allocator
<char>, M
{ };
45 // This test uses { target std_allocator_new } so this is true too:
46 STATIC_ASSERT( sizeof(D
) == 1 );