]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/align/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / align / 1.cc
CommitLineData
52066eae 1// { dg-do run { target c++11 } }
2f6ca9d3
RS
2
3// 2014-04-16 Rüdiger Sonderfeld <ruediger@c-plusplus.de>
4
a945c346 5// Copyright (C) 2014-2024 Free Software Foundation, Inc.
2f6ca9d3
RS
6//
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
11// version.
12
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.
17
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/>.
21
22// C++11 [ptr.align] (20.6.5): std::align
23
facb4d1b
JW
24// { dg-require-cstdint "" }
25
2f6ca9d3
RS
26#include <memory>
27#include <cstdint>
28#include <testsuite_hooks.h>
29
30void
31test01()
32{
13feb023
JW
33 using std::size_t;
34
2f6ca9d3
RS
35 size_t space = 100;
36 void* ptr = new char[space];
37 char* const orig_ptr = static_cast<char*>(ptr);
38 char* old_ptr = orig_ptr;
39 const size_t orig_space = space;
40 size_t old_space = space;
41 const size_t alignment = 16;
42 const size_t size = 10;
43 while( void* const r = std::align(alignment, size, ptr, space) )
44 {
45 VERIFY( r == ptr );
46 uintptr_t p = reinterpret_cast<uintptr_t>(ptr);
47 VERIFY( p % alignment == 0 );
48 char* const x = static_cast<char*>(ptr);
13feb023 49 VERIFY( size_t(x - old_ptr) == old_space - space );
2f6ca9d3
RS
50 VERIFY( (void*)x < (void*)(orig_ptr + orig_space) );
51 VERIFY( (void*)(x + size) < (void*)(orig_ptr + orig_space) );
52 ptr = x + size;
53 old_ptr = x;
54 old_space = space;
55 space -= size;
56 }
57 delete [] orig_ptr;
58}
59
60int main()
61{
62 test01();
63}