]> 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
85ec4feb 5// Copyright (C) 2014-2018 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{
2f6ca9d3
RS
33 size_t space = 100;
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) )
42 {
43 VERIFY( r == ptr );
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) );
50 ptr = x + size;
51 old_ptr = x;
52 old_space = space;
53 space -= size;
54 }
55 delete [] orig_ptr;
56}
57
58int main()
59{
60 test01();
61}