+2019-10-31 Jonathan Wakely <jwakely@redhat.com>
+
+ * testsuite/24_iterators/range_access*.cc: Move to ...
+ * testsuite/24_iterators/range_access/range_access*.cc: ... here.
+ * testsuite/24_iterators/range_access/range_access_cpp20_neg.cc: New
+ test.
+
2019-10-30 Jonathan Wakely <jwakely@redhat.com>
* include/std/concepts (std::ranges::swap): Use a single overload for
+++ /dev/null
-// { dg-do compile { target c++11 } }
-
-// Copyright (C) 2010-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/>.
-
-// C++ 2011 24.6.5, range access [iterator.range]
-
-#include <iterator>
-
-void
-test01()
-{
- int arr[3] = {1, 2, 3};
- std::begin(arr);
- std::end(arr);
-}
--- /dev/null
+// { dg-do compile { target c++11 } }
+
+// Copyright (C) 2010-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/>.
+
+// C++ 2011 24.6.5, range access [iterator.range]
+
+#include <iterator>
+
+void
+test01()
+{
+ int arr[3] = {1, 2, 3};
+ std::begin(arr);
+ std::end(arr);
+}
--- /dev/null
+// { dg-do run { target c++14 } }
+
+// Copyright (C) 2015-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/>.
+
+// C++ 2014 24.7, range access [iterator.range]
+
+#include <iterator>
+#include <vector>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ int i[1];
+ VERIFY(std::cbegin(i) == i);
+ VERIFY(std::cend(i) == i+1);
+ VERIFY(std::rbegin(i) == std::reverse_iterator<int*>(i+1));
+ VERIFY(std::rend(i) == std::reverse_iterator<int*>(i));
+ VERIFY(std::crbegin(i) == std::reverse_iterator<int*>(i+1));
+ VERIFY(std::crend(i) == std::reverse_iterator<int*>(i));
+}
+
+void
+test02()
+{
+ static int i[1];
+ constexpr auto b __attribute__((unused)) = std::begin(i);
+ constexpr auto e __attribute__((unused)) = std::end(i);
+ constexpr auto cb __attribute__((unused)) = std::cbegin(i);
+ constexpr auto ce __attribute__((unused)) = std::cend(i);
+}
+
+void
+test03()
+{
+ std::initializer_list<int> il{1};
+ VERIFY(std::cbegin(il) == il.begin());
+ VERIFY(std::cend(il) == il.end());
+ VERIFY(std::rbegin(il) == std::reverse_iterator<const int*>(il.end()));
+ VERIFY(std::rend(il) == std::reverse_iterator<const int*>(il.begin()));
+ VERIFY(std::crbegin(il) == std::reverse_iterator<const int*>(il.end()));
+ VERIFY(std::crend(il) == std::reverse_iterator<const int*>(il.begin()));
+}
+
+void
+test04()
+{
+ std::vector<int> v{1};
+ VERIFY(std::cbegin(v) == v.cbegin());
+ VERIFY(std::cend(v) == v.cend());
+ VERIFY(std::rbegin(v) == v.rbegin());
+ VERIFY(std::rend(v) == v.rend());
+ VERIFY(std::crbegin(v) == v.crbegin());
+ VERIFY(std::crend(v) == v.crend());
+}
+
+int
+main()
+{
+ test01();
+ test02();
+ test03();
+ test04();
+}
--- /dev/null
+// { dg-options "-std=gnu++17" }
+// { dg-do compile { target c++17 } }
+
+// Copyright (C) 2017-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/>.
+
+// C++ 2017 27.7, range access [iterator.range]
+
+#include <iterator>
+
+void
+test01()
+{
+ using std::reverse_iterator;
+ static int i[1];
+ static_assert(std::cbegin(i) == i);
+ static_assert(std::cend(i) == i+1);
+ static_assert(std::rbegin(i) == reverse_iterator<int*>(i+1));
+ static_assert(std::rend(i) == reverse_iterator<int*>(i));
+ static_assert(std::crbegin(i) == reverse_iterator<int*>(i+1));
+ static_assert(std::crend(i) == reverse_iterator<int*>(i));
+}
+
+void
+test02()
+{
+ static int i[] = { 1, 2 };
+ static_assert(std::distance(std::begin(i), std::end(i)) == 2);
+ static_assert(std::distance(std::cbegin(i), std::cend(i)) == 2);
+}
+
+void
+test03()
+{
+ using std::reverse_iterator;
+ static constexpr std::initializer_list<int> il{1};
+ static_assert(std::cbegin(il) == il.begin());
+ static_assert(std::cend(il) == il.end());
+ static_assert(std::rbegin(il) == reverse_iterator<const int*>(il.end()));
+ static_assert(std::rend(il) == reverse_iterator<const int*>(il.begin()));
+ static_assert(std::crbegin(il) == reverse_iterator<const int*>(il.end()));
+ static_assert(std::crend(il) == reverse_iterator<const int*>(il.begin()));
+}
--- /dev/null
+// Copyright (C) 2017-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++17" }
+// { dg-do compile { target c++17 } }
+
+#include <iterator>
+#include <initializer_list>
+
+void
+test01()
+{
+ struct A { bool empty() const { return true; } };
+ A a;
+ std::empty(a); // { dg-warning "ignoring return value" }
+}
+
+void
+test02()
+{
+ int a[2];
+ std::empty(a); // { dg-warning "ignoring return value" }
+}
+
+void
+test03()
+{
+ std::initializer_list<int> a{};
+ std::empty(a); // { dg-warning "ignoring return value" }
+}
--- /dev/null
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+// 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/>.
+
+// N4830 23.7, Range access [iterator.range]
+
+#include <iterator>
+
+void
+test01()
+{
+ static int i[1];
+ constexpr auto s = std::ssize(i);
+ const std::ptrdiff_t* check_type = &s;
+ static_assert(s == 1);
+}
+
+void
+test02()
+{
+ static int i[] = { 1, 2 };
+ constexpr auto s = std::ssize(i);
+ const std::ptrdiff_t* check_type = &s;
+ static_assert(s == 2);
+}
+
+void
+test03()
+{
+ struct Cont
+ {
+ constexpr unsigned short size() const { return 3; }
+ };
+ constexpr Cont c;
+ constexpr auto s = std::ssize(c);
+ const std::ptrdiff_t* check_type = &s;
+ static_assert(s == 3);
+}
+
+void
+test04()
+{
+ struct Cont
+ {
+ constexpr unsigned long long size() const { return 4; }
+ };
+ constexpr Cont c;
+ constexpr auto s = std::ssize(c);
+ const long long* check_type = &s;
+ static_assert(s == 4);
+}
--- /dev/null
+// 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 <iterator>
+
+void
+test01()
+{
+ struct C { unsigned size() { return 0u; } };
+ C c;
+ std::ssize(c); // { dg-error "no matching function" }
+}
+// { dg-error "discards qualifiers" "" { target *-*-* } 0 }
+
+void
+test02()
+{
+ struct C { bool size() { return false; } };
+ C c;
+ std::ssize(c); // { dg-error "no matching function" }
+}
+// { dg-error "incomplete type .*make_signed.*bool" "" { target *-*-* } 0 }
+
+void
+test03()
+{
+ struct S { };
+ struct C { S size() { return {}; } };
+ C c;
+ std::ssize(c); // { dg-error "no matching function" }
+}
+// { dg-error "incomplete type .*make_signed.*S" "" { target *-*-* } 0 }
+++ /dev/null
-// { dg-do run { target c++14 } }
-
-// Copyright (C) 2015-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/>.
-
-// C++ 2014 24.7, range access [iterator.range]
-
-#include <iterator>
-#include <vector>
-#include <testsuite_hooks.h>
-
-void
-test01()
-{
- int i[1];
- VERIFY(std::cbegin(i) == i);
- VERIFY(std::cend(i) == i+1);
- VERIFY(std::rbegin(i) == std::reverse_iterator<int*>(i+1));
- VERIFY(std::rend(i) == std::reverse_iterator<int*>(i));
- VERIFY(std::crbegin(i) == std::reverse_iterator<int*>(i+1));
- VERIFY(std::crend(i) == std::reverse_iterator<int*>(i));
-}
-
-void
-test02()
-{
- static int i[1];
- constexpr auto b __attribute__((unused)) = std::begin(i);
- constexpr auto e __attribute__((unused)) = std::end(i);
- constexpr auto cb __attribute__((unused)) = std::cbegin(i);
- constexpr auto ce __attribute__((unused)) = std::cend(i);
-}
-
-void
-test03()
-{
- std::initializer_list<int> il{1};
- VERIFY(std::cbegin(il) == il.begin());
- VERIFY(std::cend(il) == il.end());
- VERIFY(std::rbegin(il) == std::reverse_iterator<const int*>(il.end()));
- VERIFY(std::rend(il) == std::reverse_iterator<const int*>(il.begin()));
- VERIFY(std::crbegin(il) == std::reverse_iterator<const int*>(il.end()));
- VERIFY(std::crend(il) == std::reverse_iterator<const int*>(il.begin()));
-}
-
-void
-test04()
-{
- std::vector<int> v{1};
- VERIFY(std::cbegin(v) == v.cbegin());
- VERIFY(std::cend(v) == v.cend());
- VERIFY(std::rbegin(v) == v.rbegin());
- VERIFY(std::rend(v) == v.rend());
- VERIFY(std::crbegin(v) == v.crbegin());
- VERIFY(std::crend(v) == v.crend());
-}
-
-int
-main()
-{
- test01();
- test02();
- test03();
- test04();
-}
+++ /dev/null
-// { dg-options "-std=gnu++17" }
-// { dg-do compile { target c++17 } }
-
-// Copyright (C) 2017-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/>.
-
-// C++ 2017 27.7, range access [iterator.range]
-
-#include <iterator>
-
-void
-test01()
-{
- using std::reverse_iterator;
- static int i[1];
- static_assert(std::cbegin(i) == i);
- static_assert(std::cend(i) == i+1);
- static_assert(std::rbegin(i) == reverse_iterator<int*>(i+1));
- static_assert(std::rend(i) == reverse_iterator<int*>(i));
- static_assert(std::crbegin(i) == reverse_iterator<int*>(i+1));
- static_assert(std::crend(i) == reverse_iterator<int*>(i));
-}
-
-void
-test02()
-{
- static int i[] = { 1, 2 };
- static_assert(std::distance(std::begin(i), std::end(i)) == 2);
- static_assert(std::distance(std::cbegin(i), std::cend(i)) == 2);
-}
-
-void
-test03()
-{
- using std::reverse_iterator;
- static constexpr std::initializer_list<int> il{1};
- static_assert(std::cbegin(il) == il.begin());
- static_assert(std::cend(il) == il.end());
- static_assert(std::rbegin(il) == reverse_iterator<const int*>(il.end()));
- static_assert(std::rend(il) == reverse_iterator<const int*>(il.begin()));
- static_assert(std::crbegin(il) == reverse_iterator<const int*>(il.end()));
- static_assert(std::crend(il) == reverse_iterator<const int*>(il.begin()));
-}
+++ /dev/null
-// Copyright (C) 2017-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++17" }
-// { dg-do compile { target c++17 } }
-
-#include <iterator>
-#include <initializer_list>
-
-void
-test01()
-{
- struct A { bool empty() const { return true; } };
- A a;
- std::empty(a); // { dg-warning "ignoring return value" }
-}
-
-void
-test02()
-{
- int a[2];
- std::empty(a); // { dg-warning "ignoring return value" }
-}
-
-void
-test03()
-{
- std::initializer_list<int> a{};
- std::empty(a); // { dg-warning "ignoring return value" }
-}
+++ /dev/null
-// { dg-options "-std=gnu++2a" }
-// { dg-do compile { target c++2a } }
-
-// 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/>.
-
-// N4830 23.7, Range access [iterator.range]
-
-#include <iterator>
-
-void
-test01()
-{
- static int i[1];
- constexpr auto s = std::ssize(i);
- const std::ptrdiff_t* check_type = &s;
- static_assert(s == 1);
-}
-
-void
-test02()
-{
- static int i[] = { 1, 2 };
- constexpr auto s = std::ssize(i);
- const std::ptrdiff_t* check_type = &s;
- static_assert(s == 2);
-}
-
-void
-test03()
-{
- struct Cont
- {
- constexpr unsigned short size() const { return 3; }
- };
- constexpr Cont c;
- constexpr auto s = std::ssize(c);
- const std::ptrdiff_t* check_type = &s;
- static_assert(s == 3);
-}
-
-void
-test04()
-{
- struct Cont
- {
- constexpr unsigned long long size() const { return 4; }
- };
- constexpr Cont c;
- constexpr auto s = std::ssize(c);
- const long long* check_type = &s;
- static_assert(s == 4);
-}