]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/18_support/exception/38732.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 18_support / exception / 38732.cc
1 // Copyright (C) 2009-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 #include <typeinfo>
19 #include <exception>
20 #include "unwind.h"
21 #include <testsuite_hooks.h>
22
23 // Before exception_ptr was introduced, some programs copied
24 // part of unwind-cxx.h and used __cxa_get_globals to get at the
25 // current exceptionType. __cxa_exception structure is described in the
26 // C++ ABI, so they have the right to assume it works.
27 // Ensure it is true.
28
29 struct __cxa_exception
30 {
31 std::type_info *exceptionType;
32 void (*exceptionDestructor)(void *);
33 std::unexpected_handler unexpectedHandler;
34 std::terminate_handler terminateHandler;
35 __cxa_exception *nextException;
36 int handlerCount;
37 #ifdef __ARM_EABI_UNWINDER__
38 __cxa_exception* nextPropagatingException;
39 int propagationCount;
40 #else
41 int handlerSwitchValue;
42 const unsigned char *actionRecord;
43 const unsigned char *languageSpecificData;
44 _Unwind_Ptr catchTemp;
45 void *adjustedPtr;
46 #endif
47 _Unwind_Exception unwindHeader;
48 };
49
50 struct __cxa_eh_globals
51 {
52 __cxa_exception *caughtExceptions;
53 unsigned int uncaughtExceptions;
54 #ifdef __ARM_EABI_UNWINDER__
55 __cxa_exception* propagatingExceptions;
56 #endif
57 };
58
59 extern "C" __cxa_eh_globals *__cxa_get_globals () throw();
60
61 // PR libstdc++/38732
62 void test01 ()
63 {
64 try {
65 throw 0;
66 } catch(...) {
67 __cxa_exception *exc = __cxa_get_globals()->caughtExceptions;
68 VERIFY ( exc != 0 );
69 VERIFY ( typeid(int) == *exc->exceptionType );
70 }
71 try {
72 throw 0LL;
73 } catch(...) {
74 __cxa_exception *exc = __cxa_get_globals()->caughtExceptions;
75 VERIFY ( exc != 0 );
76 VERIFY ( typeid(long long int) == *exc->exceptionType );
77 }
78 try {
79 throw 0.0;
80 } catch(...) {
81 __cxa_exception *exc = __cxa_get_globals()->caughtExceptions;
82 VERIFY ( exc != 0 );
83 VERIFY ( typeid(double) == *exc->exceptionType );
84 }
85 }
86
87 int main ()
88 {
89 test01 ();
90 }