]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/align/3.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / align / 3.cc
1 // { dg-do run { target c++11 } }
2
3 // 2020-09-20 Glen Joseph Fernandes <glenjofe@gmail.com>
4
5 // Copyright (C) 2020-2021 Free Software Foundation, Inc.
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
24 #include <memory>
25 #include <testsuite_hooks.h>
26
27 void test01()
28 {
29 void* p1 = reinterpret_cast<void*>(5);
30 void* p2 = p1;
31 std::size_t s1 = 3072;
32 std::size_t s2 = s1;
33 VERIFY(std::align(1024, static_cast<std::size_t>(-1), p1, s1) == nullptr);
34 VERIFY(p1 == p2);
35 VERIFY(s1 == s2);
36 }
37
38 void test02()
39 {
40 void* p1 = reinterpret_cast<void*>(1);
41 void* p2 = p1;
42 std::size_t s1 = -1;
43 std::size_t s2 = s1;
44 VERIFY(std::align(2, static_cast<std::size_t>(-1), p1, s1) == nullptr);
45 VERIFY(p1 == p2);
46 VERIFY(s1 == s2);
47 }
48
49 int main()
50 {
51 test01();
52 test02();
53 }