summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite
diff options
context:
space:
mode:
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2014-12-22 16:00:16 +0000
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2014-12-22 16:00:16 +0000
commitd3ab86117a4b67ca76491e13e4f705cfb9efb79e (patch)
treeb5cd8e6aea671c3f1c0fd2c4280e643555c216fb /libstdc++-v3/testsuite
parent9bc2e56c8ce78f2d98e0c4398cbc81284e216b26 (diff)
downloadgcc-d3ab86117a4b67ca76491e13e4f705cfb9efb79e.tar.gz
2014-12-22 Ville Voutilainen <ville.voutilainen@gmail.com>
PR libstdc++/60271 C++14 constexpr min, max, minmax, min_element, max_element and minmax_element. Also constexpr for 20.9.5-20.9.9, aka various library functors. * include/bits/c++config: Add _GLIBCXX14_CONSTEXPR. * include/bits/algorithmfwd.h (min, max, minmax, min_element, max_element): Use it. * include/bits/predefined_ops.h (_Iter_less_iter, __iter_less_iter, _Iter_comp_iter, __iter_comp_iter): Likewise. * include/bits/stl_algo.h (minmax, __minmax_element, minmax_element, min, max, __min_element, min_element, __max_element, max_element) Likewise. * include/bits/stl_algobase.h (min, max): Likewise. * include/bits/stl_function.h (plus, minus, multiplies, divides, modulus, negate, equal_to, not_equal_to, greater, less, greater_equal, less_equal, logical_and, logical_or, logical_not, bit_and, bit_or, bit_xor, bit_not, unary_negate, not1, binary_negate, not2): Likewise. * testsuite/20_util/function_objects/constexpr.cc: New. * testsuite/25_algorithms/max/constexpr.cc: Likewise. * testsuite/25_algorithms/max_element/constexpr.cc: Likewise. * testsuite/25_algorithms/min/constexpr.cc: Likewise. * testsuite/25_algorithms/min_element/constexpr.cc: Likewise. * testsuite/25_algorithms/minmax/constexpr.cc: Likewise. * testsuite/25_algorithms/minmax_element/constexpr.cc: Likewise. * testsuite/ext/profile/mutex_extensions_neg.cc: Adjust dg-error. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@219015 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/testsuite')
-rw-r--r--libstdc++-v3/testsuite/20_util/function_objects/constexpr.cc77
-rw-r--r--libstdc++-v3/testsuite/25_algorithms/max/constexpr.cc28
-rw-r--r--libstdc++-v3/testsuite/25_algorithms/max_element/constexpr.cc29
-rw-r--r--libstdc++-v3/testsuite/25_algorithms/min/constexpr.cc28
-rw-r--r--libstdc++-v3/testsuite/25_algorithms/min_element/constexpr.cc29
-rw-r--r--libstdc++-v3/testsuite/25_algorithms/minmax/constexpr.cc32
-rw-r--r--libstdc++-v3/testsuite/25_algorithms/minmax_element/constexpr.cc33
-rw-r--r--libstdc++-v3/testsuite/ext/profile/mutex_extensions_neg.cc2
8 files changed, 257 insertions, 1 deletions
diff --git a/libstdc++-v3/testsuite/20_util/function_objects/constexpr.cc b/libstdc++-v3/testsuite/20_util/function_objects/constexpr.cc
new file mode 100644
index 00000000000..3ad7e0dbee4
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/function_objects/constexpr.cc
@@ -0,0 +1,77 @@
+// { dg-options "-std=gnu++14" }
+// { dg-do compile }
+
+// Copyright (C) 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/>.
+
+// 20.9.5-20.9.9
+
+#include <functional>
+
+static_assert(std::plus<int>()(1,2)==3, "");
+static_assert(std::minus<int>()(3,2)==1, "");
+static_assert(std::multiplies<int>()(3,2)==6, "");
+static_assert(std::divides<int>()(6,2)==3, "");
+static_assert(std::modulus<int>()(7,2)==1, "");
+static_assert(std::negate<int>()(-5)==5, "");
+
+static_assert(std::plus<void>()(1,2)==3, "");
+static_assert(std::minus<void>()(3,2)==1, "");
+static_assert(std::multiplies<void>()(3,2)==6, "");
+static_assert(std::divides<void>()(6,2)==3, "");
+static_assert(std::modulus<void>()(7,2)==1, "");
+static_assert(std::negate<void>()(-5)==5, "");
+
+static_assert(std::equal_to<int>()(2,2), "");
+static_assert(std::not_equal_to<int>()(1,2), "");
+static_assert(std::greater<int>()(2,1), "");
+static_assert(std::less<int>()(1,2), "");
+static_assert(std::greater_equal<int>()(2,2), "");
+static_assert(std::less_equal<int>()(2,2), "");
+
+static_assert(std::equal_to<void>()(2,2), "");
+static_assert(std::not_equal_to<void>()(1,2), "");
+static_assert(std::greater<void>()(2,1), "");
+static_assert(std::less<void>()(1,2), "");
+static_assert(std::greater_equal<void>()(2,2), "");
+static_assert(std::less_equal<void>()(2,2), "");
+
+static_assert(std::logical_and<int>()(1,1), "");
+static_assert(std::logical_or<int>()(0,1), "");
+static_assert(std::logical_not<int>()(0), "");
+
+static_assert(std::logical_and<void>()(1,1), "");
+static_assert(std::logical_or<void>()(0,1), "");
+static_assert(std::logical_not<void>()(0), "");
+
+static_assert(std::bit_and<int>()(3,2)==2, "");
+static_assert(std::bit_or<int>()(1,2)==3, "");
+static_assert(std::bit_xor<int>()(1,1)==0, "");
+static_assert(std::bit_not<int>()(std::bit_not<int>()(0))==0, "");
+
+static_assert(std::bit_and<void>()(3,2)==2, "");
+static_assert(std::bit_or<void>()(1,2)==3, "");
+static_assert(std::bit_xor<void>()(1,1)==0, "");
+static_assert(std::bit_not<void>()(std::bit_not<void>()(0))==0, "");
+
+static_assert(std::unary_negate<std::logical_not<int>>
+ (std::logical_not<int>())(1), "");
+static_assert(std::not1(std::logical_not<int>())(1), "");
+
+static_assert(std::binary_negate<std::logical_and<int>>
+ (std::logical_and<int>())(0,0), "");
+static_assert(std::not2(std::logical_and<int>())(0,0), "");
diff --git a/libstdc++-v3/testsuite/25_algorithms/max/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/max/constexpr.cc
new file mode 100644
index 00000000000..3db6d8f1054
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/max/constexpr.cc
@@ -0,0 +1,28 @@
+// { dg-options "-std=gnu++14" }
+// { dg-do compile }
+
+// Copyright (C) 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/>.
+
+#include <algorithm>
+#include <functional>
+
+static_assert(std::max(1, 2) == 2, "");
+static_assert(std::max(2, 1, std::greater<int>()) == 1, "");
+static_assert(std::max({1, 2}) == 2, "");
+static_assert(std::max({2, 1}, std::greater<int>())==1, "");
+
diff --git a/libstdc++-v3/testsuite/25_algorithms/max_element/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/max_element/constexpr.cc
new file mode 100644
index 00000000000..666dad875dd
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/max_element/constexpr.cc
@@ -0,0 +1,29 @@
+// { dg-options "-std=gnu++14" }
+// { dg-do compile }
+
+// Copyright (C) 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/>.
+
+#include <algorithm>
+#include <functional>
+#include <utility>
+
+constexpr std::initializer_list<int> test{1, 2};
+
+static_assert(*std::max_element(test.begin(), test.end()) == 2, "");
+static_assert(*std::max_element(test.begin(), test.end(),
+ std::greater<int>()) == 1, "");
diff --git a/libstdc++-v3/testsuite/25_algorithms/min/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/min/constexpr.cc
new file mode 100644
index 00000000000..615b18c8b03
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/min/constexpr.cc
@@ -0,0 +1,28 @@
+// { dg-options "-std=gnu++14" }
+// { dg-do compile }
+
+// Copyright (C) 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/>.
+
+#include <algorithm>
+#include <functional>
+
+static_assert(std::min(2, 1) == 1, "");
+static_assert(std::min(2, 1, std::greater<int>()) == 2, "");
+static_assert(std::min({2, 1}) == 1, "");
+static_assert(std::min({1, 2}, std::greater<int>())==2, "");
+
diff --git a/libstdc++-v3/testsuite/25_algorithms/min_element/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/min_element/constexpr.cc
new file mode 100644
index 00000000000..376be83542d
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/min_element/constexpr.cc
@@ -0,0 +1,29 @@
+// { dg-options "-std=gnu++14" }
+// { dg-do compile }
+
+// Copyright (C) 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/>.
+
+#include <algorithm>
+#include <functional>
+#include <utility>
+
+constexpr std::initializer_list<int> test{2, 1};
+
+static_assert(*std::min_element(test.begin(), test.end()) == 1, "");
+static_assert(*std::min_element(test.begin(), test.end(),
+ std::greater<int>()) == 2, "");
diff --git a/libstdc++-v3/testsuite/25_algorithms/minmax/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/minmax/constexpr.cc
new file mode 100644
index 00000000000..cd5d95ee713
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/minmax/constexpr.cc
@@ -0,0 +1,32 @@
+// { dg-options "-std=gnu++14" }
+// { dg-do compile }
+
+// Copyright (C) 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/>.
+
+#include <algorithm>
+#include <functional>
+#include <utility>
+
+static_assert(std::minmax(2, 1) ==
+ std::pair<const int&, const int&>(1, 2), "");
+static_assert(std::minmax(2, 1, std::greater<int>()) ==
+ std::pair<const int&, const int&>(2, 1), "");
+static_assert(std::minmax({2, 1}) ==
+ std::pair<int, int>(1, 2), "");
+static_assert(std::minmax({2, 1}, std::greater<int>())==
+ std::pair<int, int>(2, 1), "");
diff --git a/libstdc++-v3/testsuite/25_algorithms/minmax_element/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/minmax_element/constexpr.cc
new file mode 100644
index 00000000000..9a79bc1259d
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/minmax_element/constexpr.cc
@@ -0,0 +1,33 @@
+// { dg-options "-std=gnu++14" }
+// { dg-do compile }
+
+// Copyright (C) 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/>.
+
+#include <algorithm>
+#include <functional>
+#include <utility>
+
+constexpr std::initializer_list<int> test{2, 1};
+constexpr auto x = std::minmax_element(test.begin(), test.end());
+constexpr auto y = std::minmax_element(test.begin(), test.end(),
+ std::greater<int>());
+static_assert(x.first == test.begin()+1, "");
+static_assert(x.second == test.begin(), "");
+static_assert(y.first == test.begin(), "");
+static_assert(y.second == test.begin()+1, "");
+
diff --git a/libstdc++-v3/testsuite/ext/profile/mutex_extensions_neg.cc b/libstdc++-v3/testsuite/ext/profile/mutex_extensions_neg.cc
index 292bee817ad..f89a1063f55 100644
--- a/libstdc++-v3/testsuite/ext/profile/mutex_extensions_neg.cc
+++ b/libstdc++-v3/testsuite/ext/profile/mutex_extensions_neg.cc
@@ -25,4 +25,4 @@
#include <vector>
-// { dg-error "multiple inlined namespaces" "" { target *-*-* } 310 }
+// { dg-error "multiple inlined namespaces" "" { target *-*-* } 318 }