diff options
author | Ville Voutilainen <ville.voutilainen@gmail.com> | 2016-11-30 11:59:50 +0200 |
---|---|---|
committer | Ville Voutilainen <ville@gcc.gnu.org> | 2016-11-30 11:59:50 +0200 |
commit | a7da4881303a7bc9a59014f0d03cd946a9cdecec (patch) | |
tree | a174bba7556763a15e784ab3eaadd32609000ff2 /libstdc++-v3/testsuite/27_io/basic_istream | |
parent | 40109581065366e04c547d2bff6e8f7ff5646fb8 (diff) | |
download | gcc-a7da4881303a7bc9a59014f0d03cd946a9cdecec.zip gcc-a7da4881303a7bc9a59014f0d03cd946a9cdecec.tar.gz gcc-a7da4881303a7bc9a59014f0d03cd946a9cdecec.tar.bz2 |
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.
From-SVN: r243006
Diffstat (limited to 'libstdc++-v3/testsuite/27_io/basic_istream')
-rw-r--r-- | libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/4.cc | 96 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/4.cc | 96 |
2 files changed, 192 insertions, 0 deletions
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(); +} |