]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_fill_n/sizes.cc
libstdc++: Handle non-integral sizes in std::uninitialized_fill_n
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / specialized_algorithms / uninitialized_fill_n / sizes.cc
CommitLineData
c9dce3b1
JW
1// Copyright (C) 2020 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.
8
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.
13
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/>.
17
18// { dg-do run }
19
20#include <memory>
21#include <testsuite_hooks.h>
22
23void
24test01()
25{
26 int i[4] = { };
27 std::uninitialized_fill_n(i, 2.0001, 0xabcd);
28 VERIFY( i[0] == 0xabcd );
29 VERIFY( i[1] == 0xabcd );
30 VERIFY( i[2] == 0xabcd );
31 VERIFY( i[3] == 0 );
32}
33
34void
35test02()
36{
37 // The standard only requires that n>0 and --n are valid expressions.
38 struct Size
39 {
40 int value;
41
42 void operator--() { --value; }
43
44 int operator>(void*) { return value != 0; }
45 };
46
47 int i[5] = { };
48 Size n = {4};
49 std::uninitialized_fill_n(i, n, 0xdcba);
50 VERIFY( i[0] == 0xdcba );
51 VERIFY( i[1] == 0xdcba );
52 VERIFY( i[2] == 0xdcba );
53 VERIFY( i[3] == 0xdcba );
54 VERIFY( i[4] == 0 );
55}
56
57int
58main()
59{
60 test01();
61 test02();
62}