Debian Codegraph @

libstdc++-v3/testsuite/20_util/any/assign/92878_92947.cc

raw symbols SCIP
1 // { dg-do run { target c++20 } }
2 // Copyright (C) 2020-2025 Free Software Foundation, Inc.
3 //
4 // This file is part of the GNU ISO C++ Library. This library is free
5 // software; you can redistribute it and/or modify it under the
6 // terms of the GNU General Public License as published by the
7 // Free Software Foundation; either version 3, or (at your option)
8 // any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this library; see the file COPYING3. If not see
17 // <http://www.gnu.org/licenses/>.
18
19 #include <any>
20 #include <testsuite_hooks.h>
21
22 struct aggressive_aggregate
23 {
24 int a;
25 int b;
26 };
27
28 void test01()
29 {
30 std::any x;
31 x.emplace<aggressive_aggregate>(1, 2);
32 VERIFY(std::any_cast<aggressive_aggregate>(x).a == 1);
33 VERIFY(std::any_cast<aggressive_aggregate>(x).b == 2);
34 x.emplace<aggressive_aggregate>(1);
35 VERIFY(std::any_cast<aggressive_aggregate>(x).a == 1);
36 VERIFY(std::any_cast<aggressive_aggregate>(x).b == 0);
37 x.emplace<aggressive_aggregate>();
38 VERIFY(std::any_cast<aggressive_aggregate>(x).a == 0);
39 VERIFY(std::any_cast<aggressive_aggregate>(x).b == 0);
40 }
41
42 int main()
43 {
44 test01();
45 }