]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/align/1.cc
1 // { dg-do run { target c++11 } }
3 // 2014-04-16 RĂ¼diger Sonderfeld <ruediger@c-plusplus.de>
5 // Copyright (C) 2014-2018 Free Software Foundation, Inc.
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the terms
9 // of the GNU General Public License as published by the Free Software
10 // Foundation; either version 3, or (at your option) any later
13 // This library is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
22 // C++11 [ptr.align] (20.6.5): std::align
24 // { dg-require-cstdint "" }
28 #include <testsuite_hooks.h>
34 void* ptr
= new char[space
];
35 char* const orig_ptr
= static_cast<char*>(ptr
);
36 char* old_ptr
= orig_ptr
;
37 const size_t orig_space
= space
;
38 size_t old_space
= space
;
39 const size_t alignment
= 16;
40 const size_t size
= 10;
41 while( void* const r
= std::align(alignment
, size
, ptr
, space
) )
44 uintptr_t p
= reinterpret_cast<uintptr_t>(ptr
);
45 VERIFY( p
% alignment
== 0 );
46 char* const x
= static_cast<char*>(ptr
);
47 VERIFY( x
- old_ptr
== old_space
- space
);
48 VERIFY( (void*)x
< (void*)(orig_ptr
+ orig_space
) );
49 VERIFY( (void*)(x
+ size
) < (void*)(orig_ptr
+ orig_space
) );