]>
Commit | Line | Data |
---|---|---|
a5544970 | 1 | // Copyright (C) 2018-2019 Free Software Foundation, Inc. |
5f302518 JW |
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-options "-D_GLIBCXX_USE_CXX11_ABI=0" } | |
19 | // { dg-do run { target c++11 } } | |
20 | ||
21 | #include <fstream> | |
22 | #include <system_error> | |
23 | #include <testsuite_hooks.h> | |
24 | ||
25 | void | |
26 | test01() | |
27 | { | |
28 | using std::ios; | |
29 | bool caught_ios_failure = false; | |
30 | bool rethrown = false; | |
31 | bool caught_system_error = false; | |
32 | try { | |
33 | std::ifstream f; | |
34 | f.exceptions(ios::failbit | ios::badbit | ios::eofbit); | |
35 | try { | |
36 | f.get(); | |
37 | } | |
38 | catch (const ios::failure&) // catch as old ABI type | |
39 | { | |
40 | caught_ios_failure = true; | |
41 | #if _GLIBCXX_USE_DUAL_ABI || _GLIBCXX_USE_CXX11_ABI == 1 | |
42 | rethrown = true; | |
43 | throw; // re-throw, to catch as new ABI type | |
44 | #endif | |
45 | } | |
46 | } | |
47 | catch (const std::system_error& e) | |
48 | { | |
49 | caught_system_error = true; | |
50 | } | |
51 | ||
52 | VERIFY( caught_ios_failure ); | |
53 | if (rethrown) | |
54 | VERIFY( caught_system_error ); | |
55 | } | |
56 | ||
57 | void | |
58 | test02() | |
59 | { | |
60 | using std::ios; | |
61 | const std::exception* p = nullptr; | |
62 | bool caught_ios_failure = false; | |
63 | bool caught_exception = false; | |
64 | try { | |
65 | std::ifstream f; | |
66 | f.exceptions(ios::failbit | ios::badbit | ios::eofbit); | |
67 | try { | |
68 | f.get(); | |
69 | } | |
70 | catch (const std::exception& e1) | |
71 | { | |
72 | caught_exception = true; | |
73 | p = &e1; | |
74 | throw; | |
75 | } | |
76 | } | |
77 | catch (const ios::failure& e2) | |
78 | { | |
79 | caught_ios_failure = true; | |
80 | #if _GLIBCXX_USE_DUAL_ABI | |
81 | // If the Dual ABI is active the library throws the new type, | |
82 | // so e1 was an object of that new type and so &e1 != &e2. | |
83 | VERIFY( p != &e2 ); | |
84 | #else | |
85 | // Otherwise there's only one type of ios::failure, so &e1 == &e2. | |
86 | VERIFY( p == &e2 ); | |
87 | #endif | |
88 | } | |
89 | ||
90 | VERIFY( caught_exception ); | |
91 | VERIFY( caught_ios_failure ); | |
92 | } | |
93 | ||
94 | int | |
95 | main() | |
96 | { | |
97 | test01(); | |
98 | test02(); | |
99 | } |