From af5b72cf9f5640d24f28398b37c7208d6b2439ab Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 26 Jun 2025 16:18:38 +0200 Subject: libstdc++: Implement C++26 P2927R3 - Inspecting exception_ptr The following patch attempts to implement the C++26 P2927R3 - Inspecting exception_ptr paper (but not including P3748R0, I plan to play with it incrementally and it will really depend on the Constexpr exceptions patch). The function template is implemented using an out of line private method of exception_ptr, so that P3748R0 then can use if consteval and provide a constant evaluation variant of it. 2025-06-26 Jakub Jelinek * include/bits/version.def (exception_ptr_cast): Add. * include/bits/version.h: Regenerate. * libsupc++/exception: Define __glibcxx_want_exception_ptr_cast before including bits/version.h. * libsupc++/exception_ptr.h (std::exception_ptr_cast): Define. (std::__exception_ptr::exception_ptr::_M_exception_ptr_cast): Declare. * libsupc++/eh_ptr.cc (std::__exception_ptr::exception_ptr::_M_exception_ptr_cast): Define. * src/c++23/std.cc.in (std::exception_ptr_cast): Export. * config/abi/pre/gnu.ver: Export _ZNKSt15__exception_ptr13exception_ptr21_M_exception_ptr_castERKSt9type_info at CXXABI_1.3.17. * testsuite/util/testsuite_abi.cc (check_version): Allow CXXABI_1.3.17. * testsuite/18_support/exception_ptr/exception_ptr_cast.cc: New test. --- .../18_support/exception_ptr/exception_ptr_cast.cc | 81 ++++++++++++++++++++++ libstdc++-v3/testsuite/util/testsuite_abi.cc | 1 + 2 files changed, 82 insertions(+) create mode 100644 libstdc++-v3/testsuite/18_support/exception_ptr/exception_ptr_cast.cc (limited to 'libstdc++-v3/testsuite') diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/exception_ptr_cast.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/exception_ptr_cast.cc new file mode 100644 index 0000000..6a6fbfe --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/exception_ptr/exception_ptr_cast.cc @@ -0,0 +1,81 @@ +// { dg-do run { target c++26 } } + +// Copyright (C) 2025 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// exception_ptr_cast. + +#include +#include + +#if __cpp_lib_exception_ptr_cast != 202506L +# error "__cpp_lib_exception_ptr_cast != 202506" +#endif + +struct A { int a; }; +struct B : A {}; +struct C : B {}; +struct D {}; +struct E : virtual C { int e; virtual ~E () {} }; +struct F : virtual E, virtual C { int f; }; +struct G : virtual F, virtual C, virtual E { + G () : g (4) { a = 1; e = 2; f = 3; } int g; +}; + +void test01() +{ + auto a = std::make_exception_ptr(C{ 42 }); + auto b = std::exception_ptr_cast(a); + VERIFY( b != nullptr ); + VERIFY( b->a == 42 ); + auto c = std::exception_ptr_cast(a); + VERIFY( c == static_cast(b) ); + auto d = std::exception_ptr_cast(a); + VERIFY( d == static_cast(b) ); + auto e = std::exception_ptr_cast(a); + VERIFY( e == nullptr ); + auto f = std::make_exception_ptr(42L); + auto g = std::exception_ptr_cast(f); + VERIFY( g != nullptr ); + VERIFY( *g == 42L ); + try + { + throw G (); + } + catch (...) + { + auto h = std::current_exception(); + auto i = std::exception_ptr_cast(h); + VERIFY( i != nullptr ); + VERIFY( i->a == 1 && i->e == 2 && i->f == 3 && i->g == 4 ); + auto j = std::exception_ptr_cast(h); + VERIFY( j == static_cast(i) ); + auto k = std::exception_ptr_cast(h); + VERIFY( k == static_cast(i) ); + auto l = std::exception_ptr_cast(h); + VERIFY( l == static_cast(i) ); + auto m = std::exception_ptr_cast(h); + VERIFY( m == static_cast(i) ); + auto n = std::exception_ptr_cast(a); + VERIFY( n == nullptr ); + } +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/util/testsuite_abi.cc b/libstdc++-v3/testsuite/util/testsuite_abi.cc index 7bffc6b..4b01023 100644 --- a/libstdc++-v3/testsuite/util/testsuite_abi.cc +++ b/libstdc++-v3/testsuite/util/testsuite_abi.cc @@ -241,6 +241,7 @@ check_version(symbol& test, bool added) #ifdef __riscv known_versions.push_back("CXXABI_1.3.16"); #endif + known_versions.push_back("CXXABI_1.3.17"); known_versions.push_back("CXXABI_IEEE128_1.3.13"); known_versions.push_back("CXXABI_TM_1"); known_versions.push_back("CXXABI_FLOAT128"); -- cgit v1.1