diff mbox

[v3] Implement LWG 2534, Constrain rvalue stream operators.

Message ID CAFk2RUaveXJfZKLZhZyJeB3iUBn2LybHi8fvWMHgkuv5LcZkpg@mail.gmail.com
State New
Headers show

Commit Message

Ville Voutilainen Nov. 27, 2016, 6:50 p.m. UTC
Tested on Linux-x64.

2016-11-27  Ville Voutilainen  <ville.voutilainen@gmail.com>

    Implement LWG 2534, Constrain rvalue stream operators.
    * include/std/istream (__is_convertible_to_basic_istream): New.
    (__is_extractable): Likewise.
    (operator>>(basic_istream<_CharT, _Traits>&&, _Tp&&)):
    Turn the stream parameter into a template parameter
    and constrain.
    * include/std/ostream /__is_convertible_to_basic_ostream): New.
    (__is_insertable): Likewise.
    (operator<<(basic_ostream<_CharT, _Traits>&&, const _Tp&)):
    Turn the stream parameter into a template parameter
    and constrain.
    * testsuite/27_io/basic_istream/extractors_other/char/4.cc: New.
    * testsuite/27_io/basic_istream/extractors_other/wchar_t/4.cc:
    Likewise.
    * testsuite/27_io/basic_ostream/inserters_other/char/6.cc: Likewise.
    * testsuite/27_io/basic_ostream/inserters_other/wchar_t/6.cc: Likewise.

Comments

Ville Voutilainen Nov. 27, 2016, 6:55 p.m. UTC | #1
On 27 November 2016 at 20:50, Ville Voutilainen
<ville.voutilainen@gmail.com> wrote:
>     * include/std/ostream /__is_convertible_to_basic_ostream): New.


And yeah, I have fixed that typo in my ChangeLog already, it should indeed be
    * include/std/ostream (__is_convertible_to_basic_ostream): New.
Jonathan Wakely Nov. 29, 2016, 8:20 p.m. UTC | #2
On 27/11/16 20:50 +0200, Ville Voutilainen wrote:
>    Implement LWG 2534, Constrain rvalue stream operators.
>    * include/std/istream (__is_convertible_to_basic_istream): New.
>    (__is_extractable): Likewise.
>    (operator>>(basic_istream<_CharT, _Traits>&&, _Tp&&)):
>    Turn the stream parameter into a template parameter
>    and constrain.
>    * include/std/ostream /__is_convertible_to_basic_ostream): New.
>    (__is_insertable): Likewise.
>    (operator<<(basic_ostream<_CharT, _Traits>&&, const _Tp&)):
>    Turn the stream parameter into a template parameter
>    and constrain.
>    * testsuite/27_io/basic_istream/extractors_other/char/4.cc: New.
>    * testsuite/27_io/basic_istream/extractors_other/wchar_t/4.cc:
>    Likewise.
>    * testsuite/27_io/basic_ostream/inserters_other/char/6.cc: Likewise.
>    * testsuite/27_io/basic_ostream/inserters_other/wchar_t/6.cc: Likewise.

OK, thanks.
diff mbox

Patch

diff --git a/libstdc++-v3/include/std/istream b/libstdc++-v3/include/std/istream
index c8a2e08..4f0e940 100644
--- a/libstdc++-v3/include/std/istream
+++ b/libstdc++-v3/include/std/istream
@@ -908,6 +908,28 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
     ws(basic_istream<_CharT, _Traits>& __is);
 
 #if __cplusplus >= 201103L
+
+  template<typename _Tp>
+    struct __is_convertible_to_basic_istream
+    {
+      template<typename _Ch, typename _Up>
+      static true_type __check(basic_istream<_Ch, _Up>*);
+
+      static false_type __check(void*);
+    public:
+      using type = decltype(__check(declval<_Tp*>()));
+      constexpr static bool value = type::value;
+  };
+
+  template<typename _Istream, typename _Tp, typename = void>
+    struct __is_extractable : false_type {};
+
+  template<typename _Istream, typename _Tp>
+    struct __is_extractable<_Istream, _Tp,
+			    __void_t<decltype(declval<_Istream&>()
+					      >> declval<_Tp>())>>
+    : true_type {};
+
   // [27.7.1.6] Rvalue stream extraction
   // _GLIBCXX_RESOLVE_LIB_DEFECTS
   // 2328. Rvalue stream extraction should use perfect forwarding
@@ -921,9 +943,14 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  rvalue streams since they won't bind to the extractor functions
    *  that take an lvalue reference.
   */
-  template<typename _CharT, typename _Traits, typename _Tp>
-    inline basic_istream<_CharT, _Traits>&
-    operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp&& __x)
+  template<typename _Istream, typename _Tp>
+    inline
+    typename enable_if<__and_<__not_<is_lvalue_reference<_Istream>>,
+			      __is_convertible_to_basic_istream<
+				typename remove_reference<_Istream>::type>,
+			      __is_extractable<_Istream&, _Tp&&>>::value,
+		       _Istream&>::type
+    operator>>(_Istream&& __is, _Tp&& __x)
     {
       __is >> std::forward<_Tp>(__x);
       return __is;
diff --git a/libstdc++-v3/include/std/ostream b/libstdc++-v3/include/std/ostream
index 0bf53f0..a1fe892 100644
--- a/libstdc++-v3/include/std/ostream
+++ b/libstdc++-v3/include/std/ostream
@@ -613,6 +613,27 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
     { return __os.flush(); }
 
 #if __cplusplus >= 201103L
+  template<typename _Tp>
+    struct __is_convertible_to_basic_ostream
+  {
+    template<typename _Ch, typename _Up>
+    static true_type __check(basic_ostream<_Ch, _Up>*);
+
+    static false_type __check(void*);
+  public:
+    using type = decltype(__check(declval<_Tp*>()));
+    constexpr static bool value = type::value;
+  };
+
+  template<typename _Ostream, typename _Tp, typename = void>
+    struct __is_insertable : false_type {};
+
+  template<typename _Ostream, typename _Tp>
+    struct __is_insertable<_Ostream, _Tp,
+			   __void_t<decltype(declval<_Ostream&>()
+					     << declval<const _Tp&>())>>
+				    : true_type {};
+
   /**
    *  @brief  Generic inserter for rvalue stream
    *  @param  __os  An input stream.
@@ -623,9 +644,15 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  rvalue streams since they won't bind to the inserter functions
    *  that take an lvalue reference.
   */
-  template<typename _CharT, typename _Traits, typename _Tp>
-    inline basic_ostream<_CharT, _Traits>&
-    operator<<(basic_ostream<_CharT, _Traits>&& __os, const _Tp& __x)
+  template<typename _Ostream, typename _Tp>
+    inline
+    typename enable_if<__and_<__not_<is_lvalue_reference<_Ostream>>,
+			      __is_convertible_to_basic_ostream<
+				typename remove_reference<_Ostream>::type>,
+			      __is_insertable<_Ostream&, const _Tp&>>::value,
+		       _Ostream&>::type
+				      //basic_ostream<_CharT, _Traits>&
+    operator<<(_Ostream&& __os, const _Tp& __x)
     {
       __os << __x;
       return __os;
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/4.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/4.cc
new file mode 100644
index 0000000..0922b0b
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/4.cc
@@ -0,0 +1,96 @@ 
+// { dg-do run { target c++11 } }
+
+// Copyright (C) 2016 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/>.
+
+// 27.6.2.5.3 basic_ostream manipulator inserters
+
+#include <sstream>
+
+struct X {};
+std::istream& operator>>(std::istream&, X&) = delete;
+
+struct Y {};
+std::istream& operator>>(std::istream& is, Y&) {return is;}
+std::istream& operator>>(std::istream& is, Y&&) {return is;}
+
+struct Z{};
+
+template <class T>
+auto f(T&&) -> decltype(void(std::declval<std::istream&>()
+			     >> std::declval<T&&>()),
+			std::true_type());
+
+std::false_type f(...);
+
+template <class T>
+auto g(T&&) -> decltype(void(std::declval<std::istream&&>()
+			     >> std::declval<T&&>()),
+			std::true_type());
+
+std::false_type g(...);
+
+void test01()
+{
+  Y y;
+  std::istringstream is;
+  is >> y;
+  is >> Y();
+  std::istringstream() >> y;
+  std::istringstream() >> Y();
+  static_assert(!std::__is_extractable<std::istream&, X&>::value, "");
+  static_assert(!std::__is_extractable<std::istream&&, X&>::value, "");
+  static_assert(!std::__is_extractable<std::istream&, X&&>::value, "");
+  static_assert(!std::__is_extractable<std::istream&&, X&&>::value, "");
+  static_assert(std::__is_extractable<std::istream&, Y&>::value, "");
+  static_assert(std::__is_extractable<std::istream&&, Y&>::value, "");
+  static_assert(std::__is_extractable<std::istream&, Y&&>::value, "");
+  static_assert(std::__is_extractable<std::istream&&, Y&&>::value, "");
+  static_assert(!std::__is_extractable<std::istream&, Z&>::value, "");
+  static_assert(!std::__is_extractable<std::istream&&, Z&>::value, "");
+  static_assert(!std::__is_extractable<std::istream&, Z&&>::value, "");
+  static_assert(!std::__is_extractable<std::istream&&, Z&&>::value, "");
+  static_assert(std::is_same<decltype(f(std::declval<X&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(f(std::declval<X&&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(f(std::declval<Y&>())),
+		std::true_type>::value, "");
+  static_assert(std::is_same<decltype(f(std::declval<Y&&>())),
+		std::true_type>::value, "");
+  static_assert(std::is_same<decltype(f(std::declval<Z&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(f(std::declval<Z&&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(g(std::declval<X&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(g(std::declval<X&&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(g(std::declval<Y&>())),
+		std::true_type>::value, "");
+  static_assert(std::is_same<decltype(g(std::declval<Y&&>())),
+		std::true_type>::value, "");
+  static_assert(std::is_same<decltype(g(std::declval<Z&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(g(std::declval<Z&&>())),
+		std::false_type>::value, "");
+}
+
+int main()
+{
+  test01();
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/4.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/4.cc
new file mode 100644
index 0000000..87c4ce4
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/4.cc
@@ -0,0 +1,96 @@ 
+// { dg-do run { target c++11 } }
+
+// Copyright (C) 2016 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/>.
+
+// 27.6.2.5.3 basic_ostream manipulator inserters
+
+#include <sstream>
+
+struct X {};
+std::wistream& operator>>(std::wistream&, X&) = delete;
+
+struct Y {};
+std::wistream& operator>>(std::wistream& is, Y&) {return is;}
+std::wistream& operator>>(std::wistream& is, Y&&) {return is;}
+
+struct Z{};
+
+template <class T>
+auto f(T&&) -> decltype(void(std::declval<std::wistream&>()
+			     >> std::declval<T&&>()),
+			std::true_type());
+
+std::false_type f(...);
+
+template <class T>
+auto g(T&&) -> decltype(void(std::declval<std::wistream&&>()
+			     >> std::declval<T&&>()),
+			std::true_type());
+
+std::false_type g(...);
+
+void test01()
+{
+  Y y;
+  std::wistringstream is;
+  is >> y;
+  is >> Y();
+  std::wistringstream() >> y;
+  std::wistringstream() >> Y();
+  static_assert(!std::__is_extractable<std::wistream&, X&>::value, "");
+  static_assert(!std::__is_extractable<std::wistream&&, X&>::value, "");
+  static_assert(!std::__is_extractable<std::wistream&, X&&>::value, "");
+  static_assert(!std::__is_extractable<std::wistream&&, X&&>::value, "");
+  static_assert(std::__is_extractable<std::wistream&, Y&>::value, "");
+  static_assert(std::__is_extractable<std::wistream&&, Y&>::value, "");
+  static_assert(std::__is_extractable<std::wistream&, Y&&>::value, "");
+  static_assert(std::__is_extractable<std::wistream&&, Y&&>::value, "");
+  static_assert(!std::__is_extractable<std::wistream&, Z&>::value, "");
+  static_assert(!std::__is_extractable<std::wistream&&, Z&>::value, "");
+  static_assert(!std::__is_extractable<std::wistream&, Z&&>::value, "");
+  static_assert(!std::__is_extractable<std::wistream&&, Z&&>::value, "");
+  static_assert(std::is_same<decltype(f(std::declval<X&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(f(std::declval<X&&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(f(std::declval<Y&>())),
+		std::true_type>::value, "");
+  static_assert(std::is_same<decltype(f(std::declval<Y&&>())),
+		std::true_type>::value, "");
+  static_assert(std::is_same<decltype(f(std::declval<Z&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(f(std::declval<Z&&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(g(std::declval<X&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(g(std::declval<X&&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(g(std::declval<Y&>())),
+		std::true_type>::value, "");
+  static_assert(std::is_same<decltype(g(std::declval<Y&&>())),
+		std::true_type>::value, "");
+  static_assert(std::is_same<decltype(g(std::declval<Z&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(g(std::declval<Z&&>())),
+		std::false_type>::value, "");
+}
+
+int main()
+{
+  test01();
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/6.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/6.cc
new file mode 100644
index 0000000..f5b27f9
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/6.cc
@@ -0,0 +1,96 @@ 
+// { dg-do run { target c++11 } }
+
+// Copyright (C) 2016 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/>.
+
+// 27.6.2.5.3 basic_ostream manipulator inserters
+
+#include <sstream>
+
+struct X {};
+std::ostream& operator<<(std::ostream&, const X&) = delete;
+
+struct Y {};
+std::ostream& operator<<(std::ostream& os, const Y&) {return os;}
+std::ostream& operator<<(std::ostream&& os, const Y&) {return os;}
+
+struct Z{};
+
+template <class T>
+auto f(T&&) -> decltype(void(std::declval<std::ostream&>()
+			     << std::declval<T&&>()),
+			std::true_type());
+
+std::false_type f(...);
+
+template <class T>
+auto g(T&&) -> decltype(void(std::declval<std::ostream&&>()
+			     << std::declval<T&&>()),
+			std::true_type());
+
+std::false_type g(...);
+
+void test01()
+{
+  Y y;
+  std::ostringstream os;
+  os << y;
+  os << Y();
+  std::ostringstream() << y;
+  std::ostringstream() << Y();
+  static_assert(!std::__is_insertable<std::ostream&, X&>::value, "");
+  static_assert(!std::__is_insertable<std::ostream&&, X&>::value, "");
+  static_assert(!std::__is_insertable<std::ostream&, X&&>::value, "");
+  static_assert(!std::__is_insertable<std::ostream&&, X&&>::value, "");
+  static_assert(std::__is_insertable<std::ostream&, Y&>::value, "");
+  static_assert(std::__is_insertable<std::ostream&&, Y&&>::value, "");
+  static_assert(std::__is_insertable<std::ostream&, Y&>::value, "");
+  static_assert(std::__is_insertable<std::ostream&&, Y&&>::value, "");
+  static_assert(!std::__is_insertable<std::ostream&, Z&>::value, "");
+  static_assert(!std::__is_insertable<std::ostream&&, Z&>::value, "");
+  static_assert(!std::__is_insertable<std::ostream&, Z&&>::value, "");
+  static_assert(!std::__is_insertable<std::ostream&&, Z&&>::value, "");
+  static_assert(std::is_same<decltype(f(std::declval<X&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(f(std::declval<X&&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(f(std::declval<Y&>())),
+		std::true_type>::value, "");
+  static_assert(std::is_same<decltype(f(std::declval<Y&&>())),
+		std::true_type>::value, "");
+  static_assert(std::is_same<decltype(f(std::declval<Z&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(f(std::declval<Z&&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(g(std::declval<X&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(g(std::declval<X&&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(g(std::declval<Y&>())),
+		std::true_type>::value, "");
+  static_assert(std::is_same<decltype(g(std::declval<Y&&>())),
+		std::true_type>::value, "");
+  static_assert(std::is_same<decltype(g(std::declval<Z&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(g(std::declval<Z&&>())),
+		std::false_type>::value, "");
+}
+
+int main()
+{
+  test01();
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/6.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/6.cc
new file mode 100644
index 0000000..1aed058
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/6.cc
@@ -0,0 +1,96 @@ 
+// { dg-do run { target c++11 } }
+
+// Copyright (C) 2016 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/>.
+
+// 27.6.2.5.3 basic_ostream manipulator inserters
+
+#include <sstream>
+
+struct X {};
+std::wostream& operator<<(std::wostream&, const X&) = delete;
+
+struct Y {};
+std::wostream& operator<<(std::wostream& os, const Y&) {return os;}
+std::wostream& operator<<(std::wostream&& os, const Y&) {return os;}
+
+struct Z{};
+
+template <class T>
+auto f(T&&) -> decltype(void(std::declval<std::wostream&>()
+			     << std::declval<T&&>()),
+			std::true_type());
+
+std::false_type f(...);
+
+template <class T>
+auto g(T&&) -> decltype(void(std::declval<std::wostream&&>()
+			     << std::declval<T&&>()),
+			std::true_type());
+
+std::false_type g(...);
+
+void test01()
+{
+  Y y;
+  std::wostringstream os;
+  os << y;
+  os << Y();
+  std::wostringstream() << y;
+  std::wostringstream() << Y();
+  static_assert(!std::__is_insertable<std::wostream&, X&>::value, "");
+  static_assert(!std::__is_insertable<std::wostream&&, X&>::value, "");
+  static_assert(!std::__is_insertable<std::wostream&, X&&>::value, "");
+  static_assert(!std::__is_insertable<std::wostream&&, X&&>::value, "");
+  static_assert(std::__is_insertable<std::wostream&, Y&>::value, "");
+  static_assert(std::__is_insertable<std::wostream&&, Y&&>::value, "");
+  static_assert(std::__is_insertable<std::wostream&, Y&>::value, "");
+  static_assert(std::__is_insertable<std::wostream&&, Y&&>::value, "");
+  static_assert(!std::__is_insertable<std::wostream&, Z&>::value, "");
+  static_assert(!std::__is_insertable<std::wostream&&, Z&>::value, "");
+  static_assert(!std::__is_insertable<std::wostream&, Z&&>::value, "");
+  static_assert(!std::__is_insertable<std::wostream&&, Z&&>::value, "");
+  static_assert(std::is_same<decltype(f(std::declval<X&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(f(std::declval<X&&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(f(std::declval<Y&>())),
+		std::true_type>::value, "");
+  static_assert(std::is_same<decltype(f(std::declval<Y&&>())),
+		std::true_type>::value, "");
+  static_assert(std::is_same<decltype(f(std::declval<Z&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(f(std::declval<Z&&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(g(std::declval<X&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(g(std::declval<X&&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(g(std::declval<Y&>())),
+		std::true_type>::value, "");
+  static_assert(std::is_same<decltype(g(std::declval<Y&&>())),
+		std::true_type>::value, "");
+  static_assert(std::is_same<decltype(g(std::declval<Z&>())),
+		std::false_type>::value, "");
+  static_assert(std::is_same<decltype(g(std::declval<Z&&>())),
+		std::false_type>::value, "");
+}
+
+int main()
+{
+  test01();
+}