aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/libsupc++
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2021-12-09 13:54:39 +0000
committerJonathan Wakely <jwakely@redhat.com>2021-12-09 23:02:37 +0000
commita1ca039fc0fe934ef36c25d8284e6e116bcaffa7 (patch)
tree0130f298f5e76dbc46ce7501c8e099dddf7a709d /libstdc++-v3/libsupc++
parenta219139e986a4200a9105d7c1fa63735d2945994 (diff)
downloadgcc-a1ca039fc0fe934ef36c25d8284e6e116bcaffa7.zip
gcc-a1ca039fc0fe934ef36c25d8284e6e116bcaffa7.tar.gz
gcc-a1ca039fc0fe934ef36c25d8284e6e116bcaffa7.tar.bz2
libstdc++: Fix std::exception_ptr regressions [PR103630]
This restores support for std::make_exception_ptr<E&> and for using std::exception_ptr in C++98. Because the new non-throwing implementation needs to use std::decay to handle references the original throwing implementation is used for C++98. We also need to change the typeid expression so it doesn't yield the dynamic type when the function parameter is a reference to a polymorphic type. Otherwise the new exception object could be caught by any handler matching the dynamic type, even though the actual exception object is only a copy of the base class, sliced to the static type. libstdc++-v3/ChangeLog: PR libstdc++/103630 * libsupc++/exception_ptr.h (exception_ptr): Fix exception specifications on inline definitions. (make_exception_ptr): Decay the template parameter. Use typeid of the static type. * testsuite/18_support/exception_ptr/103630.cc: New test.
Diffstat (limited to 'libstdc++-v3/libsupc++')
-rw-r--r--libstdc++-v3/libsupc++/exception_ptr.h19
1 files changed, 13 insertions, 6 deletions
diff --git a/libstdc++-v3/libsupc++/exception_ptr.h b/libstdc++-v3/libsupc++/exception_ptr.h
index f9dffd5..f597524 100644
--- a/libstdc++-v3/libsupc++/exception_ptr.h
+++ b/libstdc++-v3/libsupc++/exception_ptr.h
@@ -39,6 +39,10 @@
#include <typeinfo>
#include <new>
+#if __cplusplus >= 201103L
+# include <bits/move.h>
+#endif
+
#ifdef _GLIBCXX_EH_PTR_RELOPS_COMPAT
# define _GLIBCXX_EH_PTR_USED __attribute__((__used__))
#else
@@ -175,13 +179,14 @@ namespace std
_GLIBCXX_EH_PTR_USED
inline
- exception_ptr::exception_ptr() _GLIBCXX_NOEXCEPT
+ exception_ptr::exception_ptr() _GLIBCXX_USE_NOEXCEPT
: _M_exception_object(0)
{ }
_GLIBCXX_EH_PTR_USED
inline
- exception_ptr::exception_ptr(const exception_ptr& __other) _GLIBCXX_NOEXCEPT
+ exception_ptr::exception_ptr(const exception_ptr& __other)
+ _GLIBCXX_USE_NOEXCEPT
: _M_exception_object(__other._M_exception_object)
{
if (_M_exception_object)
@@ -232,14 +237,16 @@ namespace std
exception_ptr
make_exception_ptr(_Ex __ex) _GLIBCXX_USE_NOEXCEPT
{
-#if __cpp_exceptions && __cpp_rtti && !_GLIBCXX_HAVE_CDTOR_CALLABI
+#if __cpp_exceptions && __cpp_rtti && !_GLIBCXX_HAVE_CDTOR_CALLABI \
+ && __cplusplus >= 201103L
+ using _Ex2 = typename remove_reference<_Ex>::type;
void* __e = __cxxabiv1::__cxa_allocate_exception(sizeof(_Ex));
(void) __cxxabiv1::__cxa_init_primary_exception(
- __e, const_cast<std::type_info*>(&typeid(__ex)),
- __exception_ptr::__dest_thunk<_Ex>);
+ __e, const_cast<std::type_info*>(&typeid(_Ex)),
+ __exception_ptr::__dest_thunk<_Ex2>);
try
{
- ::new (__e) _Ex(__ex);
+ ::new (__e) _Ex2(std::forward<_Ex>(__ex));
return exception_ptr(__e);
}
catch(...)