diff options
Diffstat (limited to 'libstdc++-v3/testsuite/20_util/bind')
-rw-r--r-- | libstdc++-v3/testsuite/20_util/bind/35569.cc | 32 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/bind/38889.cc | 31 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/bind/42593.cc | 31 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/bind/45924.cc | 45 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/bind/49058_1.cc | 34 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/bind/49058_2.cc | 28 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/bind/all_bound.cc | 39 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/bind/conv_result.cc | 49 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/bind/cv_quals.cc | 119 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/bind/cv_quals_2.cc | 49 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/bind/move.cc | 58 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/bind/nested.cc | 42 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/bind/placeholders.cc | 40 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/bind/ref.cc | 55 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/bind/ref2.cc | 63 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/bind/ref_neg.cc | 59 |
16 files changed, 774 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/20_util/bind/35569.cc b/libstdc++-v3/testsuite/20_util/bind/35569.cc new file mode 100644 index 000000000..8d25f1a8a --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/35569.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2010 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/>. + +// 20.7.11 Function template bind + +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +#include <functional> + +using namespace std; +using namespace std::placeholders; + +void test01() +{ + bind(multiplies<int>(),4,_1)(5); +} + diff --git a/libstdc++-v3/testsuite/20_util/bind/38889.cc b/libstdc++-v3/testsuite/20_util/bind/38889.cc new file mode 100644 index 000000000..b4f47c6c4 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/38889.cc @@ -0,0 +1,31 @@ +// Copyright (C) 2010 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/>. + +// 20.7.11 Function template bind + +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +#include <functional> + +void goo(int); +void foo() { + std::bind (goo,1)(); + std::bind (goo,std::placeholders::_1)(1); +} + + diff --git a/libstdc++-v3/testsuite/20_util/bind/42593.cc b/libstdc++-v3/testsuite/20_util/bind/42593.cc new file mode 100644 index 000000000..327d1df54 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/42593.cc @@ -0,0 +1,31 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// Copyright (C) 2010 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/>. + +// 20.7.11 Function template bind + +#include <functional> + +void f( int ) {} + +void test01() +{ + std::function< void( int ) > pf = std::bind( &f, std::placeholders::_1 ); + pf(1); +} + diff --git a/libstdc++-v3/testsuite/20_util/bind/45924.cc b/libstdc++-v3/testsuite/20_util/bind/45924.cc new file mode 100644 index 000000000..27adb70c0 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/45924.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2010 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/>. + +#include <functional> + +// PR libstdc++/45924 + +struct f +{ + int operator()(int, int) const { return 0; } +}; + +void test01() +{ + int i = 0; + using namespace std::placeholders; + auto b = std::bind<int>(f(), _1, _2); + auto const bc(b); + b(i, i); + bc(i, i); +} + +int main() +{ + test01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/20_util/bind/49058_1.cc b/libstdc++-v3/testsuite/20_util/bind/49058_1.cc new file mode 100644 index 000000000..fb34e0878 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/49058_1.cc @@ -0,0 +1,34 @@ +// { dg-options "-pedantic -std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2011 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/>. + +#include <functional> + +// PR libstdc++/49058 + +struct F +{ + void + operator()(); +}; + +void f() +{ + std::bind( F() ); +} diff --git a/libstdc++-v3/testsuite/20_util/bind/49058_2.cc b/libstdc++-v3/testsuite/20_util/bind/49058_2.cc new file mode 100644 index 000000000..fc9d9a254 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/49058_2.cc @@ -0,0 +1,28 @@ +// { dg-options "-pedantic -std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2011 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/>. + +#include <functional> + +// PR libstdc++/49058 + +void f() +{ + std::bind( []{} ); +} diff --git a/libstdc++-v3/testsuite/20_util/bind/all_bound.cc b/libstdc++-v3/testsuite/20_util/bind/all_bound.cc new file mode 100644 index 000000000..4335ee1d1 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/all_bound.cc @@ -0,0 +1,39 @@ +// { dg-options "-std=gnu++0x" } +// Copyright (C) 2009 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/>. + +// 20.7.11 Function template bind + +#include <functional> +#include <testsuite_hooks.h> + +// Operations on empty function<> objects +void test01() +{ + bool test __attribute__((unused)) = true; + + VERIFY( std::bind(std::plus<int>(), 3, 5)() == 8 ); + VERIFY( std::bind(std::minus<int>(), 3, 5)() == -2 ); + VERIFY( std::bind<int>(std::plus<int>(), 3, 5)() == 8 ); + VERIFY( std::bind<int>(std::minus<int>(), 3, 5)() == -2 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bind/conv_result.cc b/libstdc++-v3/testsuite/20_util/bind/conv_result.cc new file mode 100644 index 000000000..440a5276b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/conv_result.cc @@ -0,0 +1,49 @@ +// { dg-options "-std=gnu++0x" } +// Copyright (C) 2009 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/>. + +// 20.7.11 Function template bind + +#include <functional> +#include <testsuite_hooks.h> + +struct X +{ + typedef int result_type; + int operator()(int i) const { return i+1; } + bool b; +}; + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::bind; + using std::ref; + ::X x = { true }; + + // test bind<R> form + bind<void>(ref(x), 1)(); + VERIFY( bind<long>(ref(x), 1)() == 2 ); + bind<void>(&::X::b, ref(x))(); + VERIFY( bind<int>(&::X::b, ref(x))() == 1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bind/cv_quals.cc b/libstdc++-v3/testsuite/20_util/bind/cv_quals.cc new file mode 100644 index 000000000..d597a56fd --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/cv_quals.cc @@ -0,0 +1,119 @@ +// Copyright (C) 2010 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/>. + +// 20.7.11 Function template bind + +// { dg-options "-std=gnu++0x" } + +#include <functional> +#include <testsuite_hooks.h> + +// target must be invoked with cv-quals of call wrapper + +struct X +{ + int operator()() { return 0; } + int operator()() const { return 1; } + int operator()() volatile { return 2; } + int operator()() const volatile { return 3; } + + int operator()(int, int, int) { return 0; } + int operator()(int, int, int) const { return 1; } + int operator()(int, int, int) volatile { return 2; } + int operator()(int, int, int) const volatile { return 3; } +}; + +using std::placeholders::_1; +using std::placeholders::_2; + +void test01() +{ + bool test __attribute__((unused)) = true; + + auto b0 = std::bind(X()); + VERIFY( b0() == 0 ); + + const auto b1 = std::bind(X()); + VERIFY( b1() == 1 ); + + volatile auto b2 = std::bind(X()); + VERIFY( b2() == 2 ); + + const volatile auto b3 = std::bind(X()); + VERIFY( b3() == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + + auto b0 = std::bind<int>(X()); + VERIFY( b0() == 0 ); + + const auto b1 = std::bind<int>(X()); + VERIFY( b1() == 1 ); + + volatile auto b2 = std::bind<int>(X()); + VERIFY( b2() == 2 ); + + const volatile auto b3 = std::bind<int>(X()); + VERIFY( b3() == 3 ); +} + +void test03() +{ + bool test __attribute__((unused)) = true; + + auto b0 = std::bind(X(), 0, _1, _2); + VERIFY( b0(0, 0) == 0 ); + + const auto b1 = std::bind(X(), _1, 0, _2); + VERIFY( b1(0, 0) == 1 ); + + volatile auto b2 = std::bind(X(), _1, _2, 0); + VERIFY( b2(0, 0) == 2 ); + + const volatile auto b3 = std::bind(X(), _1, 0, _2); + VERIFY( b3(0, 0) == 3 ); +} + +void test04() +{ + bool test __attribute__((unused)) = true; + + auto b0 = std::bind<int>(X(), 0, _1, _2); + VERIFY( b0(0, 0) == 0 ); + + const auto b1 = std::bind<int>(X(), _1, 0, _2); + VERIFY( b1(0, 0) == 1 ); + + volatile auto b2 = std::bind<int>(X(), _1, _2, 0); + VERIFY( b2(0, 0) == 2 ); + + const volatile auto b3 = std::bind<int>(X(), _1, 0, _2); + VERIFY( b3(0, 0) == 3 ); +} + + +int main() +{ + test01(); + test02(); + test03(); + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bind/cv_quals_2.cc b/libstdc++-v3/testsuite/20_util/bind/cv_quals_2.cc new file mode 100644 index 000000000..067d862b4 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/cv_quals_2.cc @@ -0,0 +1,49 @@ +// Copyright (C) 2011 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-options "-std=gnu++0x" } + +#include <functional> +#include <testsuite_hooks.h> + +struct X +{ + int operator()() const { return 0; } + int operator()() volatile { return 1; } + int operator()() const volatile { return 2; } + void operator()() { }; +}; + +void test01() +{ + bool test __attribute__((unused)) = true; + + const auto b0 = std::bind(X()); + VERIFY( b0() == 0 ); + + volatile auto b1 = std::bind(X()); + VERIFY( b1() == 1 ); + + const volatile auto b2 = std::bind(X()); + VERIFY( b2() == 2 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bind/move.cc b/libstdc++-v3/testsuite/20_util/bind/move.cc new file mode 100644 index 000000000..d9485ad31 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/move.cc @@ -0,0 +1,58 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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/>. + +#include <functional> +#include <testsuite_hooks.h> + +// PR libstdc++/45924 + +struct f +{ + f() : i(0) { } + f(f&& r) : i(1) { r.i = -1; } + f(const f&) = delete; + int operator()() { return i; } + int i; +}; + +void test01() +{ + auto b = std::bind(f()); + VERIFY( b() == 1 ); + auto bc(std::move(b)); + VERIFY( bc() == 1 ); + VERIFY( b() == -1 ); +} + +void test02() +{ + auto b = std::bind<int>(f()); + VERIFY( b() == 1 ); + auto bc(std::move(b)); + VERIFY( bc() == 1 ); + VERIFY( b() == -1 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/20_util/bind/nested.cc b/libstdc++-v3/testsuite/20_util/bind/nested.cc new file mode 100644 index 000000000..ae3a16686 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/nested.cc @@ -0,0 +1,42 @@ +// { dg-options "-std=gnu++0x" } +// Copyright (C) 2009 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/>. + +// 20.7.11 Function template bind + +#include <functional> +#include <testsuite_hooks.h> + +// Operations on empty function<> objects +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std::placeholders; + + int five = 5; + int seven = 7; + VERIFY( std::bind(std::multiplies<int>(), _1, + std::bind(std::minus<int>(), 6, _2))(five, seven) == -5 ); + VERIFY( std::bind(std::multiplies<int>(), _1, + std::bind(std::minus<int>(), 6, _2))(seven, five) == 7 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bind/placeholders.cc b/libstdc++-v3/testsuite/20_util/bind/placeholders.cc new file mode 100644 index 000000000..fc0d9c64f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/placeholders.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++0x" } +// Copyright (C) 2009 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/>. + +// 20.7.11 Function template bind + +#include <functional> +#include <testsuite_hooks.h> + +// Operations on empty function<> objects +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std::placeholders; + + int five = 5; + int seven = 7; + VERIFY( std::bind(std::minus<int>(), _1, _2)(five, seven) == -2 ); + VERIFY( std::bind(std::minus<int>(), _2, _1)(five, seven) == 2 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bind/ref.cc b/libstdc++-v3/testsuite/20_util/bind/ref.cc new file mode 100644 index 000000000..6b41f1887 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/ref.cc @@ -0,0 +1,55 @@ +// { dg-options "-std=gnu++0x" } +// Copyright (C) 2009 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/>. + +// 20.7.11 Function template bind + +#include <functional> +#include <testsuite_hooks.h> + +struct X +{ + X() : bar(17) {} + + int foo(int x, int y) { return bar + x + y; } + + int bar; + +private: + X(const X&); + X& operator=(const X&); +}; + +// Operations on empty function<> objects +void test01() +{ + bool test __attribute__((unused)) = true; + using std::bind; + using std::ref; + ::X x; + + VERIFY( bind(&::X::foo, ref(x), 1, 2)() == 20 ); + VERIFY( bind<int>(&::X::foo, ref(x), 1, 2)() == 20 ); + VERIFY( bind(&::X::bar, ref(x))() == 17 ); + VERIFY( bind<int>(&::X::bar, ref(x))() == 17 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bind/ref2.cc b/libstdc++-v3/testsuite/20_util/bind/ref2.cc new file mode 100644 index 000000000..614943157 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/ref2.cc @@ -0,0 +1,63 @@ +// Copyright (C) 2010 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/>. + +// 20.7.11 Function template bind + +// { dg-options "-std=gnu++0x" } + +#include <functional> +#include <testsuite_hooks.h> + +using namespace std::placeholders; + +int inc(int& i) { return ++i; } + +void test01() +{ + bool test __attribute__((unused)) = true; + + int counter = 0; + std::bind(&inc, _1)(counter); + VERIFY(counter == 1 ); + std::bind(&inc, std::ref(counter))(); + VERIFY(counter == 2 ); +} + +struct Inc +{ + int operator()(int& i) const { return ++i; } + void operator()(int&&) const { } + + int f(int& i) const { return ++i; } +}; + +void test02() +{ + bool test __attribute__((unused)) = true; + + int counter = 0; + std::bind(Inc(), _1)(counter); + VERIFY(counter == 1 ); + std::bind(&Inc::f, Inc(), std::ref(counter))(); + VERIFY(counter == 2 ); +} + +int main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/20_util/bind/ref_neg.cc b/libstdc++-v3/testsuite/20_util/bind/ref_neg.cc new file mode 100644 index 000000000..060bf8715 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/ref_neg.cc @@ -0,0 +1,59 @@ +// Copyright (C) 2010 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/>. + +// 20.7.11 Function template bind + +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +#include <functional> + +using namespace std::placeholders; + +int inc(int& i) { return ++i; } + +void test01() +{ + const int dummy = 0; + std::bind(&inc, _1)(0); // { dg-error ""} + std::bind(&inc, std::ref(dummy))(); // { dg-error ""} + std::bind(&inc, dummy)(); // { dg-error ""} + std::bind(&inc, 0)(); // { dg-error ""} +} + +struct Inc +{ + int operator()(int& i) const { return ++i; } + void operator()(int&&) const { } + + int f(int&& i) const { return ++i; } +}; + +void test02() +{ + const int dummy = 0; + std::bind(Inc(), _1)(dummy); // { dg-error ""} + std::bind(&Inc::f, Inc(), std::ref(dummy))(); // { dg-error ""} +} + +int main() +{ + test01(); + test02(); +} + +// { dg-excess-errors "" } |