diff options
author | Ben Cheng <bccheng@google.com> | 2014-03-25 22:37:19 -0700 |
---|---|---|
committer | Ben Cheng <bccheng@google.com> | 2014-03-25 22:37:19 -0700 |
commit | 1bc5aee63eb72b341f506ad058502cd0361f0d10 (patch) | |
tree | c607e8252f3405424ff15bc2d00aa38dadbb2518 /gcc-4.9/libstdc++-v3/testsuite/20_util/function_objects/mem_fn/55463.cc | |
parent | 283a0bf58fcf333c58a2a92c3ebbc41fb9eb1fdb (diff) | |
download | toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.gz toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.bz2 toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.zip |
Initial checkin of GCC 4.9.0 from trunk (r208799).
Change-Id: I48a3c08bb98542aa215912a75f03c0890e497dba
Diffstat (limited to 'gcc-4.9/libstdc++-v3/testsuite/20_util/function_objects/mem_fn/55463.cc')
-rw-r--r-- | gcc-4.9/libstdc++-v3/testsuite/20_util/function_objects/mem_fn/55463.cc | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/gcc-4.9/libstdc++-v3/testsuite/20_util/function_objects/mem_fn/55463.cc b/gcc-4.9/libstdc++-v3/testsuite/20_util/function_objects/mem_fn/55463.cc new file mode 100644 index 000000000..9c5dbcb55 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/20_util/function_objects/mem_fn/55463.cc @@ -0,0 +1,112 @@ +// { dg-options "-std=gnu++11" } +// { dg-do compile } + +// Copyright (C) 2012-2014 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; +}; + +struct Y : X { }; + +using CX = const X; +using CY = const Y; + +using X_ptr = X*; + +struct smart_ptr +{ + X& operator*() const; +}; + +std::reference_wrapper<X> ref(); +std::reference_wrapper<const X> cref(); +std::reference_wrapper<Y> yref(); + +void test01() +{ + int& i1 __attribute__((unused)) = std::mem_fn( &X::func )( X() ); + int& i2 __attribute__((unused)) = std::mem_fn( &X::func )( Y() ); + int& i3 __attribute__((unused)) = std::mem_fn( &X::func )( ref() ); + int& i4 __attribute__((unused)) = std::mem_fn( &X::func )( yref() ); + int& i5 __attribute__((unused)) = std::mem_fn( &X::func )( X_ptr() ); + int& i6 __attribute__((unused)) = std::mem_fn( &X::func )( smart_ptr() ); + + char& c1 __attribute__((unused)) = std::mem_fn( &X::func_c )( X() ); + char& c2 __attribute__((unused)) = std::mem_fn( &X::func_c )( CX() ); + char& c3 __attribute__((unused)) = std::mem_fn( &X::func_c )( Y() ); + char& c4 __attribute__((unused)) = std::mem_fn( &X::func_c )( ref() ); + char& c5 __attribute__((unused)) = std::mem_fn( &X::func_c )( cref() ); + char& c6 __attribute__((unused)) = std::mem_fn( &X::func_c )( yref() ); + char& c7 __attribute__((unused)) = std::mem_fn( &X::func_c )( X_ptr() ); + char& c8 __attribute__((unused)) = std::mem_fn( &X::func_c )( smart_ptr() ); + + short& s1 __attribute__((unused)) = std::mem_fn( &X::func_v )( X() ); + short& s2 __attribute__((unused)) = std::mem_fn( &X::func_v )( Y() ); + short& s3 __attribute__((unused)) = std::mem_fn( &X::func_v )( ref() ); + short& s4 __attribute__((unused)) = std::mem_fn( &X::func_v )( yref() ); + short& s5 __attribute__((unused)) = std::mem_fn( &X::func_v )( X_ptr() ); + short& s6 __attribute__((unused)) = std::mem_fn( &X::func_v )( smart_ptr() ); + + double& d1 __attribute__((unused)) = std::mem_fn( &X::func_cv )( X() ); + double& d2 __attribute__((unused)) = std::mem_fn( &X::func_cv )( CX() ); + double& d3 __attribute__((unused)) = std::mem_fn( &X::func_cv )( Y() ); + double& d4 __attribute__((unused)) = std::mem_fn( &X::func_cv )( ref() ); + double& d5 __attribute__((unused)) = std::mem_fn( &X::func_cv )( cref() ); + double& d6 __attribute__((unused)) = std::mem_fn( &X::func_cv )( yref() ); + double& d7 __attribute__((unused)) = std::mem_fn( &X::func_cv )( X_ptr() ); + double& d8 __attribute__((unused)) + = std::mem_fn( &X::func_cv )( smart_ptr() ); + + // [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 __attribute__((unused)) = std::mem_fn( &X::data )( X() ); + const int&& crval __attribute__((unused)) = std::mem_fn( &X::data )( CX() ); + int&& yrval __attribute__((unused)) = std::mem_fn( &X::data )( Y() ); + const int&& ycrval __attribute__((unused)) = std::mem_fn( &X::data )( CY() ); + + int& val __attribute__((unused)) = std::mem_fn( &X::data )( ref() ); + const int& cval __attribute__((unused)) = std::mem_fn( &X::data )( cref() ); + int& yval __attribute__((unused)) = std::mem_fn( &X::data )( yref() ); + + int& pval __attribute__((unused)) = std::mem_fn( &X::data )( X_ptr() ); + int& sval __attribute__((unused)) = std::mem_fn( &X::data )( smart_ptr() ); +} + +void test02() +{ + std::reference_wrapper<X> r = ref(); + X& x1 __attribute__((unused)) + = std::mem_fn( &std::reference_wrapper<X>::get )( r ); + const std::reference_wrapper<X> cr = ref(); + const X& x3 __attribute__((unused)) + = std::mem_fn( &std::reference_wrapper<X>::get )( cr ); + X& x2 __attribute__((unused)) + = std::mem_fn( &std::reference_wrapper<X>::get )( ref() ); +} |