]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/19_diagnostics/logic_error/what-3.cc
freestanding.cc: Prefer -std=gnu++11.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 19_diagnostics / logic_error / what-3.cc
1 // { dg-options "-std=gnu++11" }
2
3 // Copyright (C) 2007-2014 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 3, or (at your option)
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
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
19
20 #include <string>
21 #include <stdexcept>
22 #include <cstring>
23 #include <testsuite_hooks.h>
24
25 // test copy ctors, assignment operators, and persistence of member string data
26 // libstdc++/1972
27 // via Greg Bumgardner <bumgard@roguewave.com>
28 void allocate_on_stack(void)
29 {
30 const size_t num = 512;
31 __extension__ char array[num];
32 for (size_t i = 0; i < num; i++)
33 array[i]=0;
34 // Suppress unused warnings.
35 for (size_t i = 0; i < num; i++)
36 array[i]=array[i];
37 }
38
39 void test04()
40 {
41 bool test __attribute__((unused)) = true;
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::logic_error obj1(s);
46
47 // block 01
48 {
49 const std::string s2(strlit1);
50 std::logic_error obj2(s2);
51 obj1 = obj2;
52 }
53 allocate_on_stack();
54 VERIFY( std::strcmp(strlit1, obj1.what()) == 0 );
55
56 // block 02
57 {
58 const std::string s3(strlit2);
59 std::logic_error obj3 = std::logic_error(s3);
60 obj1 = obj3;
61 }
62 allocate_on_stack();
63 VERIFY( std::strcmp(strlit2, obj1.what()) == 0 );
64 }
65
66 int main(void)
67 {
68 test04();
69 return 0;
70 }