]>
Commit | Line | Data |
---|---|---|
b2dad0e3 BK |
1 | // 1999-09-20 bkoz |
2 | ||
99dee823 | 3 | // Copyright (C) 1999-2021 Free Software Foundation, Inc. |
b2dad0e3 BK |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
b2dad0e3 BK |
9 | // any later version. |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | ||
16 | // You should have received a copy of the GNU General Public License along | |
748086b7 JJ |
17 | // with this library; see the file COPYING3. If not see |
18 | // <http://www.gnu.org/licenses/>. | |
b2dad0e3 | 19 | |
b2dad0e3 | 20 | |
23cac885 | 21 | // 27.4.3 template class fpos |
b2dad0e3 | 22 | |
23cac885 BK |
23 | #include <cwchar> // for mbstate_t |
24 | #include <ios> | |
1b716e90 | 25 | #include <cstring> |
f13a69ec | 26 | #include <testsuite_hooks.h> |
b2dad0e3 | 27 | |
bcc6a03a BK |
28 | void test01() |
29 | { | |
23cac885 | 30 | typedef std::mbstate_t state_type; |
7a900bce AO |
31 | // Use zero-initialization of the underlying memory so that padding |
32 | // bytes, if any, stand a better chance of comparing the same. | |
33 | // Zero-initialized memory is guaranteed to be a valid initial | |
34 | // state. This doesn't quite guarantee that any padding bits won't | |
35 | // be overwritten when copying from other instances that haven't | |
36 | // been fully initialized: this data type is compatible with C, so | |
37 | // it is likely plain old data, but it could have a default ctor | |
38 | // that initializes only the relevant fields, whereas copy-ctor and | |
39 | // operator= could be implemented as a full-object memcpy, including | |
40 | // padding bits, rather than fieldwise copying. However, since | |
41 | // we're comparing two values copied from the same state_type | |
42 | // instance, if padding bits are copied, we'll get the same for both | |
43 | // of them, and if they aren't, we'll keep the values we initialized | |
44 | // them with, so this should be good. | |
45 | state_type state[2]; | |
46 | std::memset(state, 0, sizeof (state)); | |
47 | ||
23cac885 | 48 | |
cc5112c9 | 49 | std::streampos pos01(0); |
23cac885 | 50 | |
23cac885 BK |
51 | // 27.4.3.1 fpos members |
52 | // void state(state_type s); | |
53 | // state_type state(); | |
cc5112c9 BK |
54 | |
55 | // XXX Need to have better sanity checking for the mbstate_t type, | |
7a900bce | 56 | // or whatever the instantiating type for class fpos happens to be |
cc5112c9 BK |
57 | // for streampos, as things like equality operators and assignment |
58 | // operators, increment and deincrement operators need to be in | |
59 | // place. | |
7a900bce AO |
60 | pos01.state(state[1]); |
61 | state[0] = pos01.state(); | |
62 | VERIFY( std::memcmp(&state[0], &state[1], sizeof(state_type)) == 0 ); | |
23cac885 | 63 | } |
b2dad0e3 | 64 | |
e6705174 BK |
65 | int main() |
66 | { | |
bcc6a03a | 67 | test01(); |
b2dad0e3 BK |
68 | return 0; |
69 | } |