diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2019-10-31 23:03:22 +0000 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2019-10-31 23:03:22 +0000 |
commit | 2670a7aa8f2680af6c113a6dec97f21d5715c809 (patch) | |
tree | 82f613b28f2cfdd2766fd23c15c8f31f99368c5a /libstdc++-v3/testsuite | |
parent | 328b52d6751733f6e0f2d31feca44e1d8f2abfc6 (diff) | |
download | gcc-2670a7aa8f2680af6c113a6dec97f21d5715c809.tar.gz |
Add remaining changes from P1065R2 "constexpr INVOKE"
* include/bits/refwrap.h (reference_wrapper, ref, cref): Add constexpr
specifiers for C++20.
* include/std/functional (_Mem_fn, mem_fn, _Bind, _Bind_result, bind)
(bind_front, _Not_fn, not_fn): Likewise.
* testsuite/20_util/bind/constexpr.cc: New test.
* testsuite/20_util/function_objects/bind_front/constexpr.cc: New test.
* testsuite/20_util/function_objects/mem_fn/constexpr.cc: New test.
* testsuite/20_util/function_objects/not_fn/constexpr.cc: New test.
* testsuite/20_util/reference_wrapper/constexpr.cc: New test.
From-SVN: r277698
Diffstat (limited to 'libstdc++-v3/testsuite')
5 files changed, 203 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/20_util/bind/constexpr.cc b/libstdc++-v3/testsuite/20_util/bind/constexpr.cc new file mode 100644 index 00000000000..6761c2c92a1 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/constexpr.cc @@ -0,0 +1,43 @@ +// Copyright (C) 2019 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++2a" } +// { dg-do compile { target c++2a } } + +#include <functional> + +struct add +{ + constexpr int operator()(int i, int j) const { return i + j; } +}; + +constexpr int +test01(int i, int j) +{ + add a; + return std::bind(a, i, std::placeholders::_1)(j); +} + +static_assert( test01(1, 2) == 3 ); + +constexpr int +test02(int i, int j) +{ + return std::bind<int>(add{}, i, std::placeholders::_1)(j); +} + +static_assert( test02(4, 5) == 9 ); diff --git a/libstdc++-v3/testsuite/20_util/function_objects/bind_front/constexpr.cc b/libstdc++-v3/testsuite/20_util/function_objects/bind_front/constexpr.cc new file mode 100644 index 00000000000..ee82745ddb7 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function_objects/bind_front/constexpr.cc @@ -0,0 +1,35 @@ +// Copyright (C) 2019 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++2a" } +// { dg-do compile { target c++2a } } + +#include <functional> + +struct add +{ + constexpr int operator()(int i, int j) const { return i + j; } +}; + +constexpr int +test01(int i, int j) +{ + add a; + return std::bind_front(a, i)(j); +} + +static_assert( test01(1, 2) == 3 ); diff --git a/libstdc++-v3/testsuite/20_util/function_objects/mem_fn/constexpr.cc b/libstdc++-v3/testsuite/20_util/function_objects/mem_fn/constexpr.cc new file mode 100644 index 00000000000..6a0d0616baa --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function_objects/mem_fn/constexpr.cc @@ -0,0 +1,45 @@ +// Copyright (C) 2019 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++2a" } +// { dg-do compile { target c++2a } } + +#include <functional> + +struct F +{ + int i; + constexpr int add(int j) { return i + j; } +}; + +constexpr int +test01(int i) +{ + F f{i}; + return std::mem_fn(&F::i)(f); +} + +static_assert( test01(2) == 2 ); + +constexpr int +test02(int i, int j) +{ + F f{i}; + return std::mem_fn(&F::add)(&f, j); +} + +static_assert( test02(3, 4) == 7 ); diff --git a/libstdc++-v3/testsuite/20_util/function_objects/not_fn/constexpr.cc b/libstdc++-v3/testsuite/20_util/function_objects/not_fn/constexpr.cc new file mode 100644 index 00000000000..1c0e737fb7d --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function_objects/not_fn/constexpr.cc @@ -0,0 +1,35 @@ +// Copyright (C) 2019 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++2a" } +// { dg-do compile { target c++2a } } + +#include <functional> + +struct F +{ + constexpr bool operator()(int i, int j) const { return i == j; } +}; + +constexpr int +test01(int i, int j) +{ + F f; + return std::not_fn(f)(1, 2); +} + +static_assert( test01(1, 2) ); diff --git a/libstdc++-v3/testsuite/20_util/reference_wrapper/constexpr.cc b/libstdc++-v3/testsuite/20_util/reference_wrapper/constexpr.cc new file mode 100644 index 00000000000..8a1c54eea7f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/reference_wrapper/constexpr.cc @@ -0,0 +1,45 @@ +// Copyright (C) 2019 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++2a" } +// { dg-do compile { target c++2a } } + +#include <functional> + +struct F +{ + constexpr int operator()(int i, int j) { return i + j; } + constexpr int operator()(int i, int j) const { return i * j; } +}; + +constexpr int +test01(int i, int j) +{ + F f; + return std::ref(std::ref(f))(i, j); +} + +static_assert( test01(1, 2) == 3 ); + +constexpr int +test02(int i, int j) +{ + F f; + return std::cref(std::cref(f))(i, j); +} + +static_assert( test02(4, 5) == 20 ); |