| 1 | // { dg-do run { target c++11 } } |
| 2 | |
| 3 | // Copyright (C) 2007-2025 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 <system_error> |
| 22 | #include <testsuite_hooks.h> |
| 23 | |
| 24 | // test copy ctors, assignment operators, and persistence of member string data |
| 25 | // libstdc++/1972 |
| 26 | // via Greg Bumgardner <[email protected]> |
| 27 | void allocate_on_stack(void) |
| 28 | { |
| 29 | const size_t num = 512; |
| 30 | __extension__ char array[num]; |
| 31 | for (size_t i = 0; i < num; i++) |
| 32 | array[i]=0; |
| 33 | // Suppress unused warnings. |
| 34 | for (size_t i = 0; i < num; i++) |
| 35 | array[i]=array[i]; |
| 36 | } |
| 37 | |
| 38 | void test04() |
| 39 | { |
| 40 | const std::string s("CA ISO emergency once again:immediate power down"); |
| 41 | const char* strlit1 = "wish I lived in Palo Alto"; |
| 42 | const char* strlit2 = "...or Santa Barbara"; |
| 43 | std::system_error obj1(std::error_code(), s); |
| 44 | |
| 45 | // block 01 |
| 46 | { |
| 47 | const std::string s2(strlit1); |
| 48 | std::system_error obj2(std::error_code(), s2); |
| 49 | obj1 = obj2; |
| 50 | } |
| 51 | allocate_on_stack(); |
| 52 | VERIFY( std::string(obj1.what()).find(strlit1) != std::string::npos ); |
| 53 | |
| 54 | // block 02 |
| 55 | { |
| 56 | const std::string s3(strlit2); |
| 57 | std::system_error obj3 = std::system_error(std::error_code(), s3); |
| 58 | obj1 = obj3; |
| 59 | } |
| 60 | allocate_on_stack(); |
| 61 | VERIFY( std::string(obj1.what()).find(strlit2) != std::string::npos ); |
| 62 | } |
| 63 | |
| 64 | int main(void) |
| 65 | { |
| 66 | test04(); |
| 67 | return 0; |
| 68 | } |