]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/19_diagnostics/runtime_error/what-3.cc
Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 19_diagnostics / runtime_error / what-3.cc
CommitLineData
0349df29
BK
1// 2001-02-26 Benjamin Kosnik <bkoz@redhat.com>
2
748086b7 3// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009
538075fe 4// Free Software Foundation, Inc.
0349df29
BK
5//
6// This file is part of the GNU ISO C++ Library. This library is free
7// software; you can redistribute it and/or modify it under the
8// terms of the GNU General Public License as published by the
748086b7 9// Free Software Foundation; either version 3, or (at your option)
0349df29
BK
10// any later version.
11
12// This library is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16
17// You should have received a copy of the GNU General Public License along
748086b7
JJ
18// with this library; see the file COPYING3. If not see
19// <http://www.gnu.org/licenses/>.
0349df29
BK
20
21// 19.1 Exception classes
22
23#include <string>
24#include <stdexcept>
538075fe 25#include <cstring>
fe413112 26#include <testsuite_hooks.h>
0349df29 27
5e984b90 28// test copy ctors, assignment operators, and persistence of member string data
9dd3d53c
BK
29// libstdc++/1972
30// via Greg Bumgardner <bumgard@roguewave.com>
31void allocate_on_stack(void)
32{
33 const size_t num = 512;
34 __extension__ char array[num];
35 for (size_t i = 0; i < num; i++)
36 array[i]=0;
37}
5e984b90 38
9dd3d53c
BK
39void test04()
40{
11f10e6b 41 bool test __attribute__((unused)) = true;
9dd3d53c
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::runtime_error obj1(s);
46
47 // block 01
48 {
49 const std::string s2(strlit1);
50 std::runtime_error obj2(s2);
51 obj1 = obj2;
52 }
53 allocate_on_stack();
eeff8d2c 54 VERIFY( std::strcmp(strlit1, obj1.what()) == 0 );
9dd3d53c
BK
55
56 // block 02
57 {
58 const std::string s3(strlit2);
59 std::runtime_error obj3 = std::runtime_error(s3);
60 obj1 = obj3;
61 }
62 allocate_on_stack();
eeff8d2c 63 VERIFY( std::strcmp(strlit2, obj1.what()) == 0 );
9dd3d53c 64}
0349df29
BK
65
66int main(void)
67{
9dd3d53c 68 test04();
0349df29
BK
69 return 0;
70}