diff options
author | Jonathan Wakely <jwakely.gcc@gmail.com> | 2012-11-26 23:53:29 +0000 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2012-11-26 23:53:29 +0000 |
commit | 5127244e4b172a5af7de329c0609971f8e181996 (patch) | |
tree | e63432f06a8153d7c527151da675b30af7fd1b7b /libstdc++-v3/testsuite/20_util | |
parent | d5b8b24b128073c2a119a9ba330b3fb7be18caa6 (diff) | |
download | gcc-5127244e4b172a5af7de329c0609971f8e181996.zip gcc-5127244e4b172a5af7de329c0609971f8e181996.tar.gz gcc-5127244e4b172a5af7de329c0609971f8e181996.tar.bz2 |
re PR libstdc++/55463 (Result of std::mem_fn doesn't accept rvalues)
PR libstdc++/55463
* include/std/functional (_Mem_fn): Handle rvalue objects. Add
noexcept-specifications.
* testsuite/20_util/function_objects/mem_fn/55463.cc: New.
* testsuite/20_util/bind/ref_neg.cc: Adjust dg-error line numbers.
From-SVN: r193831
Diffstat (limited to 'libstdc++-v3/testsuite/20_util')
-rw-r--r-- | libstdc++-v3/testsuite/20_util/bind/ref_neg.cc | 8 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/function_objects/mem_fn/55463.cc | 78 |
2 files changed, 82 insertions, 4 deletions
diff --git a/libstdc++-v3/testsuite/20_util/bind/ref_neg.cc b/libstdc++-v3/testsuite/20_util/bind/ref_neg.cc index 0f1b4cf..c7f605e 100644 --- a/libstdc++-v3/testsuite/20_util/bind/ref_neg.cc +++ b/libstdc++-v3/testsuite/20_util/bind/ref_neg.cc @@ -30,10 +30,10 @@ void test01() { const int dummy = 0; std::bind(&inc, _1)(0); // { dg-error "no match" } - // { dg-error "rvalue|const" "" { target *-*-* } 1208 } - // { dg-error "rvalue|const" "" { target *-*-* } 1222 } - // { dg-error "rvalue|const" "" { target *-*-* } 1236 } - // { dg-error "rvalue|const" "" { target *-*-* } 1250 } + // { dg-error "rvalue|const" "" { target *-*-* } 1224 } + // { dg-error "rvalue|const" "" { target *-*-* } 1238 } + // { dg-error "rvalue|const" "" { target *-*-* } 1252 } + // { dg-error "rvalue|const" "" { target *-*-* } 1266 } std::bind(&inc, std::ref(dummy))(); // { dg-error "no match" } } diff --git a/libstdc++-v3/testsuite/20_util/function_objects/mem_fn/55463.cc b/libstdc++-v3/testsuite/20_util/function_objects/mem_fn/55463.cc new file mode 100644 index 0000000..5adce1b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function_objects/mem_fn/55463.cc @@ -0,0 +1,78 @@ +// { dg-options "-std=gnu++11" } +// { dg-do compile } + +// Copyright (C) 2012 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/>. + +// PR libstdc++/55463 Passing rvalue objects to std::mem_fn + +#include <functional> + +struct X +{ + int& func(); + char& func_c() const; + short& func_v() volatile; + double& func_cv() const volatile; + + int data; +}; + +using CX = const X; + +struct smart_ptr +{ + X& operator*() const; +}; + +std::reference_wrapper<X> ref(); +std::reference_wrapper<const X> cref(); + +void test01() +{ + int& i1 = std::mem_fn( &X::func )( X() ); + int& i2 = std::mem_fn( &X::func )( smart_ptr() ); + int& i3 = std::mem_fn( &X::func )( ref() ); + + char& c1 = std::mem_fn( &X::func_c )( X() ); + char& c2 = std::mem_fn( &X::func_c )( CX() ); + char& c3 = std::mem_fn( &X::func_c )( smart_ptr() ); + char& c4 = std::mem_fn( &X::func_c )( ref() ); + char& c5 = std::mem_fn( &X::func_c )( cref() ); + + short& s1 = std::mem_fn( &X::func_v )( X() ); + short& s2 = std::mem_fn( &X::func_v )( smart_ptr() ); + short& s3 = std::mem_fn( &X::func_v )( ref() ); + + double& d1 = std::mem_fn( &X::func_cv )( X() ); + double& d2 = std::mem_fn( &X::func_cv )( CX() ); + double& d3 = std::mem_fn( &X::func_cv )( smart_ptr() ); + double& d4 = std::mem_fn( &X::func_cv )( ref() ); + double& d5 = std::mem_fn( &X::func_cv )( cref() ); + + // [expr.mptr.oper] + // The result of a .* expression whose second operand is a pointer to a + // data member is of the same value category (3.10) as its first operand. + int&& rval = std::mem_fn( &X::data )( X() ); + const int&& crval = std::mem_fn( &X::data )( CX() ); + + int& sval = std::mem_fn( &X::data )( smart_ptr() ); + + int& val = std::mem_fn( &X::data )( ref() ); + const int& cval = std::mem_fn( &X::data )( cref() ); +} + |