I added a static assertion to enforce the CopyConstructible
requirement that the standard imposes for std::throw_with_nested.
Unfortunately the standard is defective, so we started rejecting
perfectly good code. This alters the check to what I think the
standard should say (and what I've proposed in a new issue against the
standard): we should check decay<T> not remove_reference<T>, because a
throw-expression decays arrays and functions to pointers.

        PR libstdc++/79114
        * libsupc++/nested_exception.h (throw_with_nested): Use decay instead
        of remove_reference.
        * testsuite/18_support/nested_exception/79114.cc: New test.

Tested powerpc64le-linux, committed to trunk.

commit f4757dfe3379d6295a44954da8eaf2a42aae624d
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Tue Jan 17 14:19:56 2017 +0000

    PR79114 use decayed type in std::throw_with_nested assertion
    
        PR libstdc++/79114
        * libsupc++/nested_exception.h (throw_with_nested): Use decay instead
        of remove_reference.
        * testsuite/18_support/nested_exception/79114.cc: New test.

diff --git a/libstdc++-v3/libsupc++/nested_exception.h 
b/libstdc++-v3/libsupc++/nested_exception.h
index 35b025a..43970b4 100644
--- a/libstdc++-v3/libsupc++/nested_exception.h
+++ b/libstdc++-v3/libsupc++/nested_exception.h
@@ -111,7 +111,7 @@ namespace std
     inline void
     throw_with_nested(_Tp&& __t)
     {
-      using _Up = typename remove_reference<_Tp>::type;
+      using _Up = typename decay<_Tp>::type;
       using _CopyConstructible
        = __and_<is_copy_constructible<_Up>, is_move_constructible<_Up>>;
       static_assert(_CopyConstructible::value,
diff --git a/libstdc++-v3/testsuite/18_support/nested_exception/79114.cc 
b/libstdc++-v3/testsuite/18_support/nested_exception/79114.cc
new file mode 100644
index 0000000..8afc72b
--- /dev/null
+++ b/libstdc++-v3/testsuite/18_support/nested_exception/79114.cc
@@ -0,0 +1,27 @@
+// Copyright (C) 2017 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/>.
+
+// { dg-do compile { target c++11 } }
+
+#include <exception>
+
+void
+test01()
+{
+  std::throw_with_nested("");
+  std::throw_with_nested(test01);
+}

Reply via email to