]>
Commit | Line | Data |
---|---|---|
0bb81a93 BK |
1 | // 2001-02-26 Benjamin Kosnik <bkoz@redhat.com> |
2 | ||
99dee823 | 3 | // Copyright (C) 2001-2021 Free Software Foundation, Inc. |
0bb81a93 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) |
0bb81a93 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/>. | |
0bb81a93 BK |
19 | |
20 | // 19.1 Exception classes | |
21 | ||
22 | #include <string> | |
23 | #include <ios> | |
24 | #include <cstring> | |
25 | #include <testsuite_hooks.h> | |
26 | ||
27 | // test copy ctors, assignment operators, and persistence of member string data | |
28 | // libstdc++/1972 | |
29 | // via Greg Bumgardner <bumgard@roguewave.com> | |
30 | void allocate_on_stack(void) | |
31 | { | |
32 | const size_t num = 512; | |
33 | __extension__ char array[num]; | |
34 | for (size_t i = 0; i < num; i++) | |
35 | array[i]=0; | |
567d4027 PC |
36 | for (size_t i = 0; i < num; i++) |
37 | array[i]=array[i]; // Suppress unused warning. | |
0bb81a93 BK |
38 | } |
39 | ||
40 | void test04() | |
41 | { | |
0bb81a93 BK |
42 | const std::string s("CA ISO emergency once again:immediate power down"); |
43 | const char* strlit1 = "wish I lived in Palo Alto"; | |
44 | const char* strlit2 = "...or Santa Barbara"; | |
45 | std::ios_base::failure obj1(s); | |
46 | ||
47 | // block 01 | |
48 | { | |
49 | const std::string s2(strlit1); | |
50 | std::ios_base::failure obj2(s2); | |
51 | obj1 = obj2; | |
52 | } | |
53 | allocate_on_stack(); | |
a5dde6dd JW |
54 | #if _GLIBCXX_USE_CXX11_ABI |
55 | VERIFY( std::strstr(obj1.what(), strlit1) != NULL ); | |
56 | #else | |
0bb81a93 | 57 | VERIFY( std::strcmp(strlit1, obj1.what()) == 0 ); |
a5dde6dd | 58 | #endif |
0bb81a93 BK |
59 | |
60 | // block 02 | |
61 | { | |
62 | const std::string s3(strlit2); | |
63 | std::ios_base::failure obj3 = std::ios_base::failure(s3); | |
64 | obj1 = obj3; | |
65 | } | |
66 | allocate_on_stack(); | |
a5dde6dd JW |
67 | #if _GLIBCXX_USE_CXX11_ABI |
68 | VERIFY( std::strstr(obj1.what(), strlit2) != NULL ); | |
69 | #else | |
0bb81a93 | 70 | VERIFY( std::strcmp(strlit2, obj1.what()) == 0 ); |
a5dde6dd | 71 | #endif |
0bb81a93 BK |
72 | } |
73 | ||
74 | int main(void) | |
75 | { | |
76 | test04(); | |
77 | return 0; | |
78 | } |