PR tree-optimization/86650 - -Warray-bounds missing inlining context
[official-gcc.git] / libstdc++-v3 / testsuite / decimal / incdec.cc
blobd2967a4d87843d7c64da971471a99bf02b7f5129
1 // Copyright (C) 2009-2018 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-require-effective-target dfp }
20 // ISO/IEC TR 24733 3.2.2.5 Increment and decrement operators (decimal32).
21 // ISO/IEC TR 24733 3.2.3.5 Increment and decrement operators (decimal64).
22 // ISO/IEC TR 24733 3.2.4.5 Increment and decrement operators (decimal128).
24 #include <decimal/decimal>
25 #include <testsuite_hooks.h>
27 // Use extension to replace implicit long long conversion with function call.
28 #define LONGLONG(X) decimal_to_long_long(X)
30 using namespace std::decimal;
32 void
33 incdec32 (void)
35 int ival;
36 decimal32 a(11), b, c;
38 // Verify that we get the expected value of b after assignment.
39 b = a;
40 ival = LONGLONG (b); VERIFY (ival == 11);
42 // Check that the increment and decrement operators change the value
43 // of the original class.
44 b = a;
45 ++b;
46 ival = LONGLONG (b); VERIFY (ival == 12);
48 b = a;
49 b++;
50 ival = LONGLONG (b); VERIFY (ival == 12);
52 b = a;
53 --b;
54 ival = LONGLONG (b); VERIFY (ival == 10);
56 b = a;
57 b--;
58 ival = LONGLONG (b); VERIFY (ival == 10);
60 // Check that the increment and decrement operators return the
61 // correct value.
62 b = a;
63 c = ++b;
64 ival = LONGLONG (c); VERIFY (ival == 12);
66 b = a;
67 c = b++;
68 ival = LONGLONG (c); VERIFY (ival == 11);
70 b = a;
71 c = --b;
72 ival = LONGLONG (c); VERIFY (ival == 10);
74 b = a;
75 c = b--;
76 ival = LONGLONG (c); VERIFY (ival == 11);
79 void
80 incdec64 (void)
82 int ival;
83 decimal64 a(11), b, c;
85 // Verify that we get the expected value of b after assignment.
86 b = a;
87 ival = LONGLONG (b); VERIFY (ival == 11);
89 // Check that the increment and decrement operators change the value
90 // of the original class.
91 b = a;
92 ++b;
93 ival = LONGLONG (b); VERIFY (ival == 12);
95 b = a;
96 b++;
97 ival = LONGLONG (b); VERIFY (ival == 12);
99 b = a;
100 --b;
101 ival = LONGLONG (b); VERIFY (ival == 10);
103 b = a;
104 b--;
105 ival = LONGLONG (b); VERIFY (ival == 10);
107 // Check that the increment and decrement operators return the
108 // correct value.
109 b = a;
110 c = ++b;
111 ival = LONGLONG (c); VERIFY (ival == 12);
113 b = a;
114 c = b++;
115 ival = LONGLONG (c); VERIFY (ival == 11);
117 b = a;
118 c = --b;
119 ival = LONGLONG (c); VERIFY (ival == 10);
121 b = a;
122 c = b--;
123 ival = LONGLONG (c); VERIFY (ival == 11);
126 void
127 incdec128 (void)
129 int ival;
130 decimal128 a(11), b, c;
132 // Verify that we get the expected value of b after assignment.
133 b = a;
134 ival = LONGLONG (b); VERIFY (ival == 11);
136 // Check that the increment and decrement operators change the value
137 // of the original class.
138 b = a;
139 ++b;
140 ival = LONGLONG (b); VERIFY (ival == 12);
142 b = a;
143 b++;
144 ival = LONGLONG (b); VERIFY (ival == 12);
146 b = a;
147 --b;
148 ival = LONGLONG (b); VERIFY (ival == 10);
150 b = a;
151 b--;
152 ival = LONGLONG (b); VERIFY (ival == 10);
154 // Check that the increment and decrement operators return the
155 // correct value.
156 b = a;
157 c = ++b;
158 ival = LONGLONG (c); VERIFY (ival == 12);
160 b = a;
161 c = b++;
162 ival = LONGLONG (c); VERIFY (ival == 11);
164 b = a;
165 c = --b;
166 ival = LONGLONG (c); VERIFY (ival == 10);
168 b = a;
169 c = b--;
170 ival = LONGLONG (c); VERIFY (ival == 11);
174 main ()
176 incdec32 ();
177 incdec64 ();
178 incdec128 ();