aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/20_util/align/3.cc
blob: aaf7941c288ea9e9f705b5d3153db4aa03697a8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// { dg-do run { target c++11 } }

// 2020-09-20 Glen Joseph Fernandes <glenjofe@gmail.com>

// Copyright (C) 2020-2025 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License as published by the Free Software
// Foundation; either version 3, or (at your option) any later
// version.

// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING3.  If not see
// <http://www.gnu.org/licenses/>.

// C++11 [ptr.align] (20.6.5): std::align

#include <memory>
#include <testsuite_hooks.h>

void test01()
{
  void* p1 = reinterpret_cast<void*>(5);
  void* p2 = p1;
  std::size_t s1 = 3072;
  std::size_t s2 = s1;
  VERIFY(std::align(1024, static_cast<std::size_t>(-1), p1, s1) == nullptr);
  VERIFY(p1 == p2);
  VERIFY(s1 == s2);
}

void test02()
{
  void* p1 = reinterpret_cast<void*>(1);
  void* p2 = p1;
  std::size_t s1 = -1;
  std::size_t s2 = s1;
  VERIFY(std::align(2, static_cast<std::size_t>(-1), p1, s1) == nullptr);
  VERIFY(p1 == p2);
  VERIFY(s1 == s2);
}

int main()
{
  test01();
  test02();
}