summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/20_util/move_if_noexcept/1.cc
blob: 078ccb83d36fabc18be99690579332c950e70948 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// { dg-do run { target c++11 } }

// 2011-04-27  Paolo Carlini  <paolo.carlini@oracle.com>
//
// Copyright (C) 2011-2018 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/>.

#include <utility>
#include <testsuite_hooks.h>

struct noexcept_move_copy
{
  noexcept_move_copy()
  : status(true)
  { };

  noexcept_move_copy(noexcept_move_copy&& r) noexcept
  { r.status = false; };

  noexcept_move_copy(const noexcept_move_copy&) = default;

  operator bool() { return status; }

private:
  bool status;
};

struct noexcept_move_no_copy
{
  noexcept_move_no_copy()
  : status(true)
  { };

  noexcept_move_no_copy(noexcept_move_no_copy&& r) noexcept
  { r.status = false; };

  noexcept_move_no_copy(const noexcept_move_no_copy&) = delete;

  operator bool() { return status; }

private:
  bool status;
};

struct except_move_copy
{
  except_move_copy()
  : status(true)
  { };

  except_move_copy(except_move_copy&& r) noexcept(false)
  { r.status = false; };

  except_move_copy(const except_move_copy&) = default;

  operator bool() { return status; }

private:
  bool status;
};

struct except_move_no_copy
{
  except_move_no_copy()
  : status(true)
  { };

  except_move_no_copy(except_move_no_copy&& r) noexcept(false)
  { r.status = false; };

  except_move_no_copy(const except_move_no_copy&) = delete;

  operator bool() { return status; }

private:
  bool status;
};

void
test01()
{
  noexcept_move_copy nemc1;
  auto nemc2 __attribute__((unused)) = std::move_if_noexcept(nemc1);
  VERIFY( nemc1 == false );

  noexcept_move_no_copy nemnc1;
  auto nemnc2 __attribute__((unused)) = std::move_if_noexcept(nemnc1);
  VERIFY( nemnc1 == false );

  except_move_copy emc1;
  auto emc2 __attribute__((unused)) = std::move_if_noexcept(emc1);
  VERIFY( emc1 == true );

  except_move_no_copy emnc1;
  auto emnc2 __attribute__((unused)) = std::move_if_noexcept(emnc1);
  VERIFY( emnc1 == false );
}

int main()
{
  test01();
  return 0;
}