#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
_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)
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(...)
--- /dev/null
+// { dg-do run }
+
+#include <exception>
+#if __cplusplus < 201103L
+// std::make_exception_ptr is defined for C++98 as a GNU extension
+# include <bits/exception_ptr.h>
+#endif
+
+#include <testsuite_hooks.h>
+
+struct B
+{
+ virtual bool derived() const { return false; }
+};
+
+struct D : B
+{
+ virtual bool derived() const { return true; }
+};
+
+int main()
+{
+ D d;
+ std::exception_ptr p = std::make_exception_ptr<B&>(d); // PR libstdc++/103630
+#if __cpp_exceptions
+ try
+ {
+ std::rethrow_exception(p);
+ }
+ catch (const D& d)
+ {
+ VERIFY(d.derived()); // PR libstdc++/103630
+ }
+ catch (const B& b)
+ {
+ VERIFY(!b.derived());
+ }
+#endif
+}