diff options
author | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-05-15 04:56:06 +0000 |
---|---|---|
committer | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-05-15 04:56:06 +0000 |
commit | 8da637123e80be2156e84d0f2f1be564132996c1 (patch) | |
tree | 3ff18ff7fc94a7ca0a414c165e33d5a33108b3f3 /libstdc++-v3 | |
parent | 8eafe656d06910682748b4f19ea12cd8bbabd4ba (diff) | |
download | gcc-8da637123e80be2156e84d0f2f1be564132996c1.tar.gz |
2009-05-15 Basile Starynkevitch <basile@starynkevitch.net>
MELT branch merged with trunk r147550
2009-05-15 Basile Starynkevitch <basile@starynkevitch.net>
merged with trunk rev147539
* gcc/melt/warmelt-normal.melt (normexp_defcmatcher): use obj_hash
instead of hashcode!
* gcc/Makefile.in: TEXI_GCCINT_FILES has both plugins.texi & melt.texi
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/melt-branch@147552 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3')
-rw-r--r-- | libstdc++-v3/ChangeLog | 58 | ||||
-rw-r--r-- | libstdc++-v3/doc/xml/manual/status_cxx200x.xml | 61 | ||||
-rw-r--r-- | libstdc++-v3/include/Makefile.am | 2 | ||||
-rw-r--r-- | libstdc++-v3/include/Makefile.in | 2 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/random.h | 29 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/random.tcc | 65 | ||||
-rw-r--r-- | libstdc++-v3/libsupc++/Makefile.am | 2 | ||||
-rw-r--r-- | libstdc++-v3/libsupc++/Makefile.in | 2 | ||||
-rw-r--r-- | libstdc++-v3/libsupc++/exception | 1 | ||||
-rw-r--r-- | libstdc++-v3/libsupc++/nested_exception.h | 177 | ||||
-rw-r--r-- | libstdc++-v3/src/compatibility.cc | 6 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/18_support/nested_exception/cons.cc | 53 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/18_support/nested_exception/nested_ptr.cc | 71 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/18_support/nested_exception/rethrow_if_nested.cc | 110 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/18_support/nested_exception/rethrow_nested.cc | 53 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/18_support/nested_exception/throw_with_nested.cc | 79 |
16 files changed, 671 insertions, 100 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 45e0f2b6b39..651b53e7164 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,6 +1,54 @@ +2009-05-14 Paolo Carlini <paolo.carlini@oracle.com> + + PR libstdc++/40123 + * random.tcc (independent_bits_engine<>::operator()()): Use + result_type(1), not 1UL. + + * random.tcc (independent_bits_engine<>::operator()()): Use _M_b.max() + and _M_b.min(), instead of this->max() and this->min(). + + * random.h (_ShiftMin1): Remove, adjust everywhere. + + * random.tcc: Minor cosmetic changes. + +2009-05-14 Paolo Carlini <paolo.carlini@oracle.com> + + * include/bits/random.tcc (cauchy_distribution<>:: + operator()(_UniformRandomNumberGenerator&, const param_type&)): + Avoid M_PI, a glibc extension. + +2009-05-13 Ben Elliston <bje@au.ibm.com> + + * include/Makefile.am (PCHFLAGS): Remove -Winvalid-pch. + * include/Makefile.in: Likewise. + +2009-05-13 Ben Elliston <bje@au.ibm.com> + + * src/compatibility.cc (_ZTIe, _ZTIPe, _ZTIPKe): Change type to + const void * const. + +2009-05-12 Edward Smith-Rowland <3dw4rd@verizon.net> + + * doc/xml/manual/status_cxx200x.xml: Note missing constexpr for + random number engines, complex, bitset, array, time utilities, and + char_traits. + +2009-05-12 Jonathan Wakely <jwakely.gcc@gmail.com> + + * libsupc++/exception: Include nested_exception.h in C++0x mode. + * libsupc++/nested_exception.h: New. + * libsupc++/Makefile.am: Add new header. + * libsupc++/Makefile.in: Regenerate. + * testsuite/18_support/nested_exception/rethrow_nested.cc: New. + * testsuite/18_support/nested_exception/throw_with_nested.cc: New. + * testsuite/18_support/nested_exception/cons.cc: New. + * testsuite/18_support/nested_exception/nested_ptr.cc: New. + * testsuite/18_support/nested_exception/rethrow_if_nested.cc: New. + * doc/xml/manual/status_cxx200x.xml: Adjust. + 2009-05-07 Paolo Carlini <paolo.carlini@oracle.com> - * include/ext/throw_allocator.h: Remove redundante include. + * include/ext/throw_allocator.h: Remove redundant include. 2009-05-07 Paolo Carlini <paolo.carlini@oracle.com> @@ -26,10 +74,10 @@ 2009-05-06 Johannes Singler <singler@ira.uka.de> - PR libstdc++/39546 - * include/parallel/algo.h (find_switch): - Parametrize binder2nd with const T& instead of T. - * testsuite/25_algorithms/find/39546.cc: new test case + PR libstdc++/39546 + * include/parallel/algo.h (find_switch): + Parametrize binder2nd with const T& instead of T. + * testsuite/25_algorithms/find/39546.cc: new test case 2009-05-06 Paolo Carlini <paolo.carlini@oracle.com> diff --git a/libstdc++-v3/doc/xml/manual/status_cxx200x.xml b/libstdc++-v3/doc/xml/manual/status_cxx200x.xml index 159bc9fec39..61b2ec2c2ab 100644 --- a/libstdc++-v3/doc/xml/manual/status_cxx200x.xml +++ b/libstdc++-v3/doc/xml/manual/status_cxx200x.xml @@ -235,10 +235,9 @@ particular release. <entry></entry> </row> <row> - <?dbhtml bgcolor="#C8B0B0" ?> <entry>18.8.6</entry> <entry>Class <code>nested_exception</code></entry> - <entry>N</entry> + <entry>Y</entry> <entry></entry> </row> <row> @@ -404,8 +403,8 @@ particular release. <row> <entry>20.3.6</entry> <entry>Class template <code>bitset</code></entry> - <entry>Y</entry> - <entry></entry> + <entry>Partial</entry> + <entry>Missing constexpr</entry> </row> <row> <entry>20.4</entry> @@ -942,8 +941,8 @@ particular release. <row> <entry>20.9.2.2</entry> <entry><code>duration_values</code></entry> - <entry>Y</entry> - <entry></entry> + <entry>Partial</entry> + <entry>Missing constexpr</entry> </row> <row> <entry>20.9.2.3</entry> @@ -954,14 +953,14 @@ particular release. <row> <entry>20.9.3</entry> <entry>Class template <code>duration</code></entry> - <entry>Y</entry> - <entry></entry> + <entry>Partial</entry> + <entry>Missing constexpr</entry> </row> <row> <entry>20.9.4</entry> <entry>Class template <code>time_point</code></entry> - <entry>Y</entry> - <entry></entry> + <entry>Partial</entry> + <entry>Missing constexpr</entry> </row> <row> <entry>20.9.5</entry> @@ -1034,26 +1033,26 @@ particular release. <row> <entry>21.2.3.1</entry> <entry>struct <code>char_traits<char></code></entry> - <entry>Y</entry> - <entry></entry> + <entry>Partial</entry> + <entry>Missing constexpr</entry> </row> <row> <entry>21.2.3.2</entry> <entry>struct <code>char_traits<char16_t></code></entry> - <entry>Y</entry> - <entry></entry> + <entry>Partial</entry> + <entry>Missing constexpr</entry> </row> <row> <entry>21.2.3.3</entry> <entry>struct <code>char_traits<char32_t></code></entry> - <entry>Y</entry> - <entry></entry> + <entry>Partial</entry> + <entry>Missing constexpr</entry> </row> <row> <entry>21.2.3.4</entry> <entry>struct <code>char_traits<wchar_t></code></entry> - <entry>Y</entry> - <entry></entry> + <entry>Partial</entry> + <entry>Missing constexpr</entry> </row> <row> <entry>21.3</entry> @@ -1325,8 +1324,8 @@ particular release. <row> <entry>23.3.1</entry> <entry>Class template <code>array</code></entry> - <entry>Y</entry> - <entry></entry> + <entry>Partial</entry> + <entry>Missing constexpr</entry> </row> <row> <entry>23.3.2</entry> @@ -1629,8 +1628,8 @@ particular release. <row> <entry>26.4</entry> <entry>Complex numbers</entry> - <entry>Y</entry> - <entry></entry> + <entry>Partial</entry> + <entry>Missing constexpr</entry> </row> <row> <entry>26.5</entry> @@ -1662,19 +1661,19 @@ particular release. <entry>26.5.3.1</entry> <entry>Class template <code>linear_congruential_engine</code></entry> <entry>Y</entry> - <entry></entry> + <entry>Missing constexpr</entry> </row> <row> <entry>26.5.3.2</entry> <entry>Class template <code>mersenne_twister_engine</code></entry> <entry>Y</entry> - <entry></entry> + <entry>Missing constexpr</entry> </row> <row> <entry>26.5.3.3</entry> <entry>Class template <code>subtract_with_carry_engine</code></entry> <entry>Y</entry> - <entry></entry> + <entry>Missing constexpr</entry> </row> <row> <entry>26.5.4</entry> @@ -1686,19 +1685,19 @@ particular release. <entry>26.5.4.1</entry> <entry>Class template <code>discard_block_engine</code></entry> <entry>Y</entry> - <entry></entry> + <entry>Missing constexpr</entry> </row> <row> <entry>26.5.4.2</entry> <entry>Class template <code>independent_bits_engine</code></entry> <entry>Y</entry> - <entry></entry> + <entry>Missing constexpr</entry> </row> <row> <entry>26.5.4.3</entry> <entry>Class template <code>shuffle_order_engine</code></entry> <entry>Y</entry> - <entry></entry> + <entry>Missing constexpr</entry> </row> <row> <entry>26.5.5</entry> @@ -1710,7 +1709,7 @@ particular release. <entry>26.5.6</entry> <entry>Class <code>random_device</code></entry> <entry>Y</entry> - <entry></entry> + <entry>Missing constexpr</entry> </row> <row> <entry>26.5.7</entry> @@ -2375,8 +2374,8 @@ particular release. <row> <entry>30.4.5.1</entry> <entry><code>once_flag</code></entry> - <entry>Y</entry> - <entry></entry> + <entry>Partial</entry> + <entry>Missing constexpr</entry> </row> <row> <entry>30.4.5.2</entry> diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index 6e7b28303e1..6a9c4f09ed4 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -852,7 +852,7 @@ pch_output_dirs = \ ${pch1_output_builddir} ${pch2_output_builddir} ${pch3_output_builddir} pch_output_anchors = \ ${pch1_output_anchor} ${pch2_output_anchor} ${pch3_output_anchor} -PCHFLAGS=-Winvalid-pch -x c++-header $(CXXFLAGS) +PCHFLAGS=-x c++-header $(CXXFLAGS) if GLIBCXX_BUILD_PCH pch_build = ${pch_output} else diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in index 5de2de6c369..0a0eeadc649 100644 --- a/libstdc++-v3/include/Makefile.in +++ b/libstdc++-v3/include/Makefile.in @@ -1089,7 +1089,7 @@ pch_output_dirs = \ pch_output_anchors = \ ${pch1_output_anchor} ${pch2_output_anchor} ${pch3_output_anchor} -PCHFLAGS = -Winvalid-pch -x c++-header $(CXXFLAGS) +PCHFLAGS = -x c++-header $(CXXFLAGS) @GLIBCXX_BUILD_PCH_FALSE@pch_build = @GLIBCXX_BUILD_PCH_TRUE@pch_build = ${pch_output} diff --git a/libstdc++-v3/include/bits/random.h b/libstdc++-v3/include/bits/random.h index 425420607ce..b5ccf8a1680 100644 --- a/libstdc++-v3/include/bits/random.h +++ b/libstdc++-v3/include/bits/random.h @@ -68,23 +68,6 @@ namespace std struct _Shift<_UIntType, __w, true> { static const _UIntType __value = _UIntType(1) << __w; }; - // XXX need constexpr - template<typename _UIntType, size_t __w, - bool = __w < static_cast<size_t> - (std::numeric_limits<_UIntType>::digits)> - struct _ShiftMin1 - { - static const _UIntType __value = - __gnu_cxx::__numeric_traits<_UIntType>::__max; - }; - - template<typename _UIntType, size_t __w> - struct _ShiftMin1<_UIntType, __w, true> - { - static const _UIntType __value = - (_UIntType(1) << __w) - _UIntType(1); - }; - template<typename _Tp, _Tp __a, _Tp __c, _Tp __m, bool> struct _Mod; @@ -395,11 +378,11 @@ namespace std static_assert(__w <= static_cast<size_t>(numeric_limits<_UIntType>::digits), "mersenne_twister_engine template arguments out of bounds"); - static_assert(__a <= __detail::_ShiftMin1<_UIntType, __w>::__value, + static_assert(__a <= (__detail::_Shift<_UIntType, __w>::__value - 1), "mersenne_twister_engine template arguments out of bounds"); - static_assert(__b <= __detail::_ShiftMin1<_UIntType, __w>::__value, + static_assert(__b <= (__detail::_Shift<_UIntType, __w>::__value - 1), "mersenne_twister_engine template arguments out of bounds"); - static_assert(__c <= __detail::_ShiftMin1<_UIntType, __w>::__value, + static_assert(__c <= (__detail::_Shift<_UIntType, __w>::__value - 1), "mersenne_twister_engine template arguments out of bounds"); public: @@ -459,7 +442,7 @@ namespace std */ result_type max() const - { return __detail::_ShiftMin1<_UIntType, __w>::__value; } + { return __detail::_Shift<_UIntType, __w>::__value - 1; } /** * @brief Discard a sequence of random numbers. @@ -644,7 +627,7 @@ namespace std */ result_type max() const - { return __detail::_ShiftMin1<_UIntType, __w>::__value; } + { return __detail::_Shift<_UIntType, __w>::__value - 1; } /** * @brief Discard a sequence of random numbers. @@ -1040,7 +1023,7 @@ namespace std */ result_type max() const - { return __detail::_ShiftMin1<_UIntType, __w>::__value; } + { return __detail::_Shift<_UIntType, __w>::__value - 1; } /** * @brief Discard a sequence of random numbers. diff --git a/libstdc++-v3/include/bits/random.tcc b/libstdc++-v3/include/bits/random.tcc index 8944c116b7e..b110f99740c 100644 --- a/libstdc++-v3/include/bits/random.tcc +++ b/libstdc++-v3/include/bits/random.tcc @@ -554,8 +554,8 @@ namespace std independent_bits_engine<_RandomNumberEngine, __w, _UIntType>:: operator()() { - const long double __r = static_cast<long double>(this->max()) - - static_cast<long double>(this->min()) + 1.0L; + const long double __r = static_cast<long double>(_M_b.max()) + - static_cast<long double>(_M_b.min()) + 1.0L; const result_type __m = std::log10(__r) / std::log10(2.0L); result_type __n, __n0, __y0, __y1, __s0, __s1; for (size_t __i = 0; __i < 2; ++__i) @@ -564,8 +564,8 @@ namespace std __n0 = __n - __w % __n; const result_type __w0 = __w / __n; const result_type __w1 = __w0 + 1; - __s0 = 1UL << __w0; - __s1 = 1UL << __w1; + __s0 = result_type(1) << __w0; + __s1 = result_type(1) << __w1; __y0 = __s0 * (__r / __s0); __y1 = __s1 * (__r / __s1); if (__r - __y0 <= __y0 / __n) @@ -577,19 +577,17 @@ namespace std { result_type __u; do - __u = _M_b() - this->min(); + __u = _M_b() - _M_b.min(); while (__u >= __y0); - __sum = __s0 * __sum - + __u % __s0; + __sum = __s0 * __sum + __u % __s0; } for (size_t __k = __n0; __k < __n; ++__k) { result_type __u; do - __u = _M_b() - this->min(); + __u = _M_b() - _M_b.min(); while (__u >= __y1); - __sum = __s1 * __sum - + __u % __s1; + __sum = __s1 * __sum + __u % __s1; } return __sum; } @@ -1653,12 +1651,11 @@ namespace std __aurng(__urng); _RealType __u; do - { - __u = __aurng(); - } + __u = __aurng(); while (__u == 0.5); - return __p.a() + __p.b() * std::tan(M_PI * __u); + const _RealType __pi = 3.1415926535897932384626433832795029L; + return __p.a() + __p.b() * std::tan(__pi * __u); } template<typename _RealType, typename _CharT, typename _Traits> @@ -2649,12 +2646,12 @@ namespace std _RandomAccessIterator __end) { typedef typename iterator_traits<_RandomAccessIterator>::value_type - __Type; + _Type; if (__begin == __end) return; - std::fill(__begin, __end, __Type(0x8b8b8b8bU)); + std::fill(__begin, __end, _Type(0x8b8b8b8bU)); const size_t __n = __end - __begin; const size_t __s = _M_v.size(); @@ -2669,21 +2666,21 @@ namespace std for (size_t __k = 0; __k < __m; ++__k) { - __Type __arg = __begin[__k % __n] - ^ __begin[(__k + __p) % __n] - ^ __begin[(__k - 1) % __n]; - __Type __r1 = __arg ^ (__arg << 27); - __r1 = __detail::__mod<__Type, 1664525U, 0U, - __detail::_Shift<__Type, 32>::__value>(__r1); - __Type __r2 = __r1; + _Type __arg = (__begin[__k % __n] + ^ __begin[(__k + __p) % __n] + ^ __begin[(__k - 1) % __n]); + _Type __r1 = __arg ^ (__arg << 27); + __r1 = __detail::__mod<_Type, 1664525U, 0U, + __detail::_Shift<_Type, 32>::__value>(__r1); + _Type __r2 = __r1; if (__k == 0) __r2 += __s; else if (__k <= __s) __r2 += __k % __n + _M_v[__k - 1]; else __r2 += __k % __n; - __r2 = __detail::__mod<__Type, 1U, 0U, - __detail::_Shift<__Type, 32>::__value>(__r2); + __r2 = __detail::__mod<_Type, 1U, 0U, + __detail::_Shift<_Type, 32>::__value>(__r2); __begin[(__k + __p) % __n] += __r1; __begin[(__k + __q) % __n] += __r2; __begin[__k % __n] = __r2; @@ -2691,15 +2688,15 @@ namespace std for (size_t __k = __m; __k < __m + __n; ++__k) { - __Type __arg = __begin[__k % __n] - + __begin[(__k + __p) % __n] - + __begin[(__k - 1) % __n]; - __Type __r3 = __arg ^ (__arg << 27); - __r3 = __detail::__mod<__Type, 1566083941U, 0U, - __detail::_Shift<__Type, 32>::__value>(__r3); - __Type __r4 = __r3 - __k % __n; - __r4 = __detail::__mod<__Type, 1U, 0U, - __detail::_Shift<__Type, 32>::__value>(__r4); + _Type __arg = (__begin[__k % __n] + + __begin[(__k + __p) % __n] + + __begin[(__k - 1) % __n]); + _Type __r3 = __arg ^ (__arg << 27); + __r3 = __detail::__mod<_Type, 1566083941U, 0U, + __detail::_Shift<_Type, 32>::__value>(__r3); + _Type __r4 = __r3 - __k % __n; + __r4 = __detail::__mod<_Type, 1U, 0U, + __detail::_Shift<_Type, 32>::__value>(__r4); __begin[(__k + __p) % __n] ^= __r4; __begin[(__k + __q) % __n] ^= __r3; __begin[__k % __n] = __r4; diff --git a/libstdc++-v3/libsupc++/Makefile.am b/libstdc++-v3/libsupc++/Makefile.am index 5c86a1efd7e..b84b5e46728 100644 --- a/libstdc++-v3/libsupc++/Makefile.am +++ b/libstdc++-v3/libsupc++/Makefile.am @@ -33,7 +33,7 @@ noinst_LTLIBRARIES = libsupc++convenience.la headers = \ exception new typeinfo cxxabi.h cxxabi-forced.h exception_defines.h \ - initializer_list exception_ptr.h + initializer_list exception_ptr.h nested_exception.h if GLIBCXX_HOSTED c_sources = \ diff --git a/libstdc++-v3/libsupc++/Makefile.in b/libstdc++-v3/libsupc++/Makefile.in index 42f57c4ec44..509a8f608ed 100644 --- a/libstdc++-v3/libsupc++/Makefile.in +++ b/libstdc++-v3/libsupc++/Makefile.in @@ -358,7 +358,7 @@ toolexeclib_LTLIBRARIES = libsupc++.la noinst_LTLIBRARIES = libsupc++convenience.la headers = \ exception new typeinfo cxxabi.h cxxabi-forced.h exception_defines.h \ - initializer_list exception_ptr.h + initializer_list exception_ptr.h nested_exception.h @GLIBCXX_HOSTED_TRUE@c_sources = \ @GLIBCXX_HOSTED_TRUE@ cp-demangle.c diff --git a/libstdc++-v3/libsupc++/exception b/libstdc++-v3/libsupc++/exception index c8b334fe945..be7dec69ab7 100644 --- a/libstdc++-v3/libsupc++/exception +++ b/libstdc++-v3/libsupc++/exception @@ -146,6 +146,7 @@ _GLIBCXX_END_NAMESPACE #if (defined(__GXX_EXPERIMENTAL_CXX0X__) \ && defined(_GLIBCXX_ATOMIC_BUILTINS_4)) #include <exception_ptr.h> +#include <nested_exception.h> #endif #endif diff --git a/libstdc++-v3/libsupc++/nested_exception.h b/libstdc++-v3/libsupc++/nested_exception.h new file mode 100644 index 00000000000..752c595b49b --- /dev/null +++ b/libstdc++-v3/libsupc++/nested_exception.h @@ -0,0 +1,177 @@ +// Nested Exception support header (nested_exception class) for -*- C++ -*- + +// Copyright (C) 2009 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. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file nested_exception.h + * This is an internal header file, included by other headers and the + * implementation. You should not attempt to use it directly. + */ + +#ifndef _GLIBCXX_NESTED_EXCEPTION_H +#define _GLIBCXX_NESTED_EXCEPTION_H 1 + +#pragma GCC visibility push(default) + +#ifndef __GXX_EXPERIMENTAL_CXX0X__ +# include <c++0x_warning.h> +#else + +#include <bits/c++config.h> + +#if !defined(_GLIBCXX_ATOMIC_BUILTINS_4) +# error This platform does not support exception propagation. +#endif + +extern "C++" { + +namespace std +{ + /** + * @addtogroup exceptions + * @{ + */ + + /// nested_exception + class nested_exception + { + public: + nested_exception() throw() : _M_ptr(current_exception()) { } + + nested_exception(const nested_exception&) throw() = default; + + nested_exception& operator=(const nested_exception&) throw() = default; + + virtual ~nested_exception() = default; + + void + rethrow_nested() const __attribute__ ((__noreturn__)) + { rethrow_exception(_M_ptr); } + + exception_ptr + nested_ptr() const + { return _M_ptr; } + + private: + exception_ptr _M_ptr; + }; + + template<typename _Except> + struct _Nested_exception : public _Except, public nested_exception + { + explicit + _Nested_exception(_Except&& __ex) + : _Except(static_cast<_Except&&>(__ex)) + { } + }; + + template<typename _Ex> + struct __get_nested_helper + { + static const nested_exception* + _S_get(const _Ex& __ex) + { + return dynamic_cast<const nested_exception*>(&__ex); + } + }; + + template<typename _Ex> + struct __get_nested_helper<_Ex*> + { + static const nested_exception* + _S_get(const _Ex* __ex) + { + return dynamic_cast<const nested_exception*>(__ex); + } + }; + + template<typename _Ex> + inline const nested_exception* + __get_nested_exception(const _Ex& __ex) + { + return __get_nested_helper<_Ex>::_S_get(__ex); + } + + template<typename _Ex> + void + __throw_with_nested(_Ex&&, const nested_exception* = 0) + __attribute__ ((__noreturn__)); + + template<typename _Ex> + void + __throw_with_nested(_Ex&&, ...) __attribute__ ((__noreturn__)); + + // This function should never be called, but is needed to avoid a warning + // about ambiguous base classes when instantiating throw_with_nested<_Ex>() + // with a type that has an accessible nested_exception base. + template<typename _Ex> + inline void + __throw_with_nested(_Ex&& __ex, const nested_exception* = 0) + { + throw __ex; + } + + template<typename _Ex> + inline void + __throw_with_nested(_Ex&& __ex, ...) + { + throw _Nested_exception<_Ex>(static_cast<_Ex&&>(__ex)); + } + + template<typename _Ex> + void + throw_with_nested(_Ex __ex) __attribute__ ((__noreturn__)); + + template<typename _Ex> + inline void + throw_with_nested(_Ex __ex) + { + if (__get_nested_exception(__ex)) + throw __ex; + __throw_with_nested(static_cast<_Ex&&>(__ex), &__ex); + } + + template<typename _Ex> + inline void + rethrow_if_nested(const _Ex& __ex) + { + if (const nested_exception* __nested = __get_nested_exception(__ex)) + __nested->rethrow_nested(); + } + + // see n2619 + inline void + rethrow_if_nested(const nested_exception& __ex) + { + __ex.rethrow_nested(); + } + + // @} group exceptions +} // namespace std + +} // extern "C++" + +#endif // __GXX_EXPERIMENTAL_CXX0X__ + +#pragma GCC visibility pop + +#endif // _GLIBCXX_NESTED_EXCEPTION_H diff --git a/libstdc++-v3/src/compatibility.cc b/libstdc++-v3/src/compatibility.cc index 1e1897cd12f..8889749eed8 100644 --- a/libstdc++-v3/src/compatibility.cc +++ b/libstdc++-v3/src/compatibility.cc @@ -502,13 +502,13 @@ extern void *_ZTVN10__cxxabiv119__pointer_type_infoE[]; extern __attribute__((used, weak)) const char _ZTSe[2] = "e"; extern __attribute__((used, weak)) const char _ZTSPe[3] = "Pe"; extern __attribute__((used, weak)) const char _ZTSPKe[4] = "PKe"; -extern __attribute__((used, weak)) const void *_ZTIe[2] +extern __attribute__((used, weak)) const void * const _ZTIe[2] = { (void *) &_ZTVN10__cxxabiv123__fundamental_type_infoE[2], (void *) _ZTSe }; -extern __attribute__((used, weak)) const void *_ZTIPe[4] +extern __attribute__((used, weak)) const void * const _ZTIPe[4] = { (void *) &_ZTVN10__cxxabiv119__pointer_type_infoE[2], (void *) _ZTSPe, (void *) 0L, (void *) _ZTIe }; -extern __attribute__((used, weak)) const void *_ZTIPKe[4] +extern __attribute__((used, weak)) const void * const _ZTIPKe[4] = { (void *) &_ZTVN10__cxxabiv119__pointer_type_infoE[2], (void *) _ZTSPKe, (void *) 1L, (void *) _ZTIe }; #endif // _GLIBCXX_LONG_DOUBLE_COMPAT diff --git a/libstdc++-v3/testsuite/18_support/nested_exception/cons.cc b/libstdc++-v3/testsuite/18_support/nested_exception/cons.cc new file mode 100644 index 00000000000..dcbd36ec7e2 --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/nested_exception/cons.cc @@ -0,0 +1,53 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009 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 +// <http://www.gnu.org/licenses/>. + +#include <exception> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::nested_exception e; + + VERIFY( !e.nested_ptr() ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + + try + { + throw 42; + } + catch (...) + { + std::nested_exception e; + VERIFY( e.nested_ptr() == std::current_exception() ); + } +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/18_support/nested_exception/nested_ptr.cc b/libstdc++-v3/testsuite/18_support/nested_exception/nested_ptr.cc new file mode 100644 index 00000000000..5a3ab62070e --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/nested_exception/nested_ptr.cc @@ -0,0 +1,71 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009 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 +// <http://www.gnu.org/licenses/>. + +#include <exception> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + try + { + throw std::nested_exception(); + } + catch (const std::nested_exception& e) + { + VERIFY( !e.nested_ptr() ); + } +} + +void test02() +{ + bool test __attribute__((unused)) = true; + + try + { + throw 42; + } + catch (...) + { + try + { + throw std::nested_exception(); + } + catch (const std::nested_exception& e) + { + try + { + std::rethrow_exception( e.nested_ptr() ); + } + catch(const int& i) + { + VERIFY( i == 42 ); + } + } + } +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/18_support/nested_exception/rethrow_if_nested.cc b/libstdc++-v3/testsuite/18_support/nested_exception/rethrow_if_nested.cc new file mode 100644 index 00000000000..37d1d80f8e8 --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/nested_exception/rethrow_if_nested.cc @@ -0,0 +1,110 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009 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 +// <http://www.gnu.org/licenses/>. + +#include <exception> +#include <testsuite_hooks.h> + +struct derived : std::nested_exception { }; + +struct base { virtual ~base() = default; }; + +struct derived2 : base, std::nested_exception { }; + +void test01() +{ + bool test __attribute__((unused)) = false; + + try + { + throw 42; + } + catch (...) + { + derived d; + try + { + std::rethrow_if_nested(d); + } + catch (const int& i) + { + test = true; + VERIFY( i == 42 ); + } + } + + VERIFY( test ); +} + +void test02() +{ + bool test __attribute__((unused)) = false; + + try + { + throw base(); + } + catch (const base& b) + { + std::rethrow_if_nested(b); + test = true; + } + + VERIFY( test ); +} + +void test03() +{ + bool test __attribute__((unused)) = false; + + try + { + throw 42; + } + catch (...) + { + try + { + throw derived2(); + } + catch (const base& b) + { + try + { + std::rethrow_if_nested(b); + } + catch (const int& i) + { + VERIFY( i == 42 ); + test = true; + } + } + } + + VERIFY( test ); +} + + +int main() +{ + test01(); + test02(); + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/18_support/nested_exception/rethrow_nested.cc b/libstdc++-v3/testsuite/18_support/nested_exception/rethrow_nested.cc new file mode 100644 index 00000000000..fca9c4c8038 --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/nested_exception/rethrow_nested.cc @@ -0,0 +1,53 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009 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 +// <http://www.gnu.org/licenses/>. + +#include <exception> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = false; + + try + { + try + { + throw 42; + } + catch (...) + { + std::nested_exception e; + e.rethrow_nested(); + } + } + catch(const int& i) + { + test = true; + VERIFY( i == 42 ); + } + + VERIFY( test ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/18_support/nested_exception/throw_with_nested.cc b/libstdc++-v3/testsuite/18_support/nested_exception/throw_with_nested.cc new file mode 100644 index 00000000000..a4f05f09f30 --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/nested_exception/throw_with_nested.cc @@ -0,0 +1,79 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009 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 +// <http://www.gnu.org/licenses/>. + +#include <exception> +#include <testsuite_hooks.h> + +struct derived : std::nested_exception { }; + +struct not_derived { virtual ~not_derived() = default; }; + +void test01() +{ + bool test __attribute__((unused)) = false; + + try + { + std::throw_with_nested(derived()); + } + catch (const std::nested_exception& e) + { + VERIFY( !e.nested_ptr() ); + try + { + throw; + } + catch (const derived&) + { + test = true; + } + } + VERIFY( test ); +} + +void test02() +{ + bool test __attribute__((unused)) = false; + + try + { + std::throw_with_nested(not_derived()); + } + catch (const std::nested_exception& e) + { + VERIFY( !e.nested_ptr() ); + try + { + throw; + } + catch (const not_derived&) + { + test = true; + } + } + VERIFY( test ); +} + +int main() +{ + test01(); + test02(); + return 0; +} |