fixed more binutils issues (newer gcc/libc)
[zpugcc/jano.git] / toolchain / gcc / libstdc++-v3 / testsuite / 19_diagnostics / stdexceptions.cc
blob30595f0f76a0e7e0c9d3ee565e67be3f7fbfe908
1 // 2001-02-26 Benjamin Kosnik <bkoz@redhat.com>
3 // Copyright (C) 2001, 2002 Free Software Foundation, Inc.
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
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
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.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
21 // 19.1 Exception classes
23 #include <string>
24 #include <stdexcept>
25 #include <testsuite_hooks.h>
27 // libstdc++/1972
28 void test01()
30 bool test __attribute__((unused)) = true;
31 std::string s("lack of sunlight, no water error");
33 // 1
34 std::logic_error obj = std::logic_error(s);
36 // 2
37 // std::logic_error obj((std::string)strlit);
39 VERIFY( std::strcmp(obj.what(), s.data()) == 0 );
42 void test02()
44 bool test __attribute__((unused)) = true;
45 std::string s("lack of sunlight error");
46 std::domain_error x(s);
48 VERIFY( std::strcmp(x.what(), s.data()) == 0 );
51 // libstdc++/2089
52 class fuzzy_logic : public std::logic_error
54 public:
55 fuzzy_logic() : std::logic_error("whoa") { }
58 void test03()
60 bool test __attribute__((unused)) = true;
61 try
62 { throw fuzzy_logic(); }
63 catch(const fuzzy_logic& obj)
64 { VERIFY( std::strcmp("whoa", obj.what()) == 0 ); }
65 catch(...)
66 { VERIFY( false ); }
69 // test copy ctors and assignment operators
70 // libstdc++/1972
71 // via Greg Bumgardner <bumgard@roguewave.com>
72 void allocate_on_stack(void)
74 const size_t num = 512;
75 __extension__ char array[num];
76 for (size_t i = 0; i < num; i++)
77 array[i]=0;
79 void test04()
81 bool test __attribute__((unused)) = true;
82 const std::string s("CA ISO emergency once again:immediate power down");
83 const char* strlit1 = "wish I lived in Palo Alto";
84 const char* strlit2 = "...or Santa Barbara";
85 std::runtime_error obj1(s);
87 // block 01
89 const std::string s2(strlit1);
90 std::runtime_error obj2(s2);
91 obj1 = obj2;
93 allocate_on_stack();
94 VERIFY( std::strcmp(strlit1, obj1.what()) == 0 );
96 // block 02
98 const std::string s3(strlit2);
99 std::runtime_error obj3 = std::runtime_error(s3);
100 obj1 = obj3;
102 allocate_on_stack();
103 VERIFY( std::strcmp(strlit2, obj1.what()) == 0 );
106 int main(void)
108 test01();
109 test02();
110 test03();
111 test04();
113 return 0;