Debian Codegraph @

libstdc++-v3/testsuite/18_support/exception_ptr/90295.cc

raw
1 // Copyright (C) 2020-2025 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // { dg-do compile { target c++11 } }
19 // { dg-options "-O1 -g0" }
20 // { dg-final { scan-assembler-not "St15__exception_ptr13exception_ptr" } }
21
22 #include <exception>
23
24 void
25 test01()
26 {
27 // PR libstdc++/90295
28 // Operations on null exception_ptr objects should be optimised away.
29
30 std::exception_ptr p1;
31 if (!(p1 == nullptr))
32 std::rethrow_exception(p1);
33
34 std::exception_ptr p2 = p1;
35 if (!(p2 == p1))
36 std::rethrow_exception(p2);
37
38 p1 = p2;
39 if (p1 != p2)
40 std::rethrow_exception(p1);
41
42 swap(p1, p2);
43 if (nullptr != p1)
44 std::rethrow_exception(p1);
45
46 p1 = std::exception_ptr(nullptr);
47 if (!(p1 == p2))
48 std::rethrow_exception(p1);
49 }