]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/any/assign/exception.cc
libstdc++: Remove redundant -std=gnu++17 option from any/optional/variant tests
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / any / assign / exception.cc
CommitLineData
6458742a 1// { dg-do run { target c++17 } }
1725d05d 2
99dee823 3// Copyright (C) 2016-2021 Free Software Foundation, Inc.
1725d05d
VV
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 <any>
21#include <testsuite_hooks.h>
22
23using std::any;
24
25bool should_throw = false;
26struct Bad
27{
28 Bad() = default;
29 Bad(const Bad&) {if (should_throw) throw 666;}
30};
31
32struct Bad2
33{
34 Bad2() = default;
35 Bad2(const Bad2&) {if (should_throw) throw 666;}
36 Bad2(Bad2&&) noexcept {}
37};
38
39int del_count = 0;
8240175b 40struct Good
1725d05d
VV
41{
42 Good() = default;
43 Good(const Good&) = default;
44 Good(Good&&) = default;
45 ~Good() {++del_count;}
46};
47
48int main()
49{
50 std::any a1 = Good();
51 del_count = 0;
52 try {
53 Bad b;
54 std::any a2 = b;
55 should_throw = true;
56 a1 = a2;
57 } catch (...) {
58 auto x = std::any_cast<Good>(a1);
118c8424
PC
59 VERIFY( del_count == 0 );
60 VERIFY( a1.has_value() );
1725d05d
VV
61 std::any_cast<Good>(a1);
62 }
63 std::any a3 = Good();
64 del_count = 0;
65 try {
66 Bad2 b;
67 std::any a4 = b;
68 should_throw = true;
69 a3 = a4;
70 } catch (...) {
71 auto x = std::any_cast<Good>(a1);
118c8424
PC
72 VERIFY( del_count == 0 );
73 VERIFY( a1.has_value() );
1725d05d
VV
74 std::any_cast<Good>(a1);
75 }
76}