]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/allocator/64135.cc
libstdc++: Disable hosted-only tests [PR103626]
[thirdparty/gcc.git] / 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 }
4
5 // PR libstdc++/64135
6
7 #define new_allocator 1
8 #define malloc_allocator 1
9 #define bitmap_allocator 1
10 #include <memory>
11
12 #if __cplusplus >= 201103L
13 #define STATIC_ASSERT(X) static_assert((X), #X)
14 #else
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]
18 #endif
19
20 #undef new_allocator
21 #undef malloc_allocator
22 #include <ext/new_allocator.h>
23 #include <ext/malloc_allocator.h>
24
25 struct N : __gnu_cxx::new_allocator<char> { };
26
27 struct A : std::allocator<char>, N { };
28 struct B : std::allocator<char> { N n; };
29
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 );
34
35 struct M : __gnu_cxx::malloc_allocator<char> { };
36 struct C : N, M { };
37
38 // Verify that malloc_allocator can be an overlapping subobject with
39 // __new_allocator:
40 STATIC_ASSERT( sizeof(M) == 1 );
41 STATIC_ASSERT( sizeof(C) == 1 );
42
43 struct D : std::allocator<char>, M { };
44
45 // This test uses { target std_allocator_new } so this is true too:
46 STATIC_ASSERT( sizeof(D) == 1 );