]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libstdc++-v3/testsuite/23_containers/map/erasure.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / map / erasure.cc
index 3b54ff598d9b7ca449aefacdb5b9d170b1c37e0d..1015c69f9f7e2a81fb1d21cac925d73825b9de8d 100644 (file)
@@ -1,7 +1,7 @@
-// { dg-options "-std=gnu++2a" }
-// { dg-do run { target c++2a } }
+// { dg-do run { target c++20 } }
+// { dg-add-options no_pch }
 
-// Copyright (C) 2018-2021 Free Software Foundation, Inc.
+// Copyright (C) 2018-2024 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
@@ -19,8 +19,6 @@
 // <http://www.gnu.org/licenses/>.
 
 #include <map>
-#include <string>
-#include <testsuite_hooks.h>
 
 #ifndef __cpp_lib_erase_if
 # error "Feature-test macro for erase_if missing in <map>"
@@ -28,6 +26,9 @@
 # error "Feature-test macro for erase_if has wrong value in <map>"
 #endif
 
+#include <string>
+#include <testsuite_hooks.h>
+
 auto is_odd_pair = [](const std::pair<const int, std::string>& p)
 {
   return p.first % 2 != 0;
@@ -61,11 +62,24 @@ test02()
   VERIFY( num == 4 );
 }
 
+void
+test_pr107850()
+{
+  // Predicate only callable as non-const and only accepts non-const argument.
+  struct Pred { bool operator()(std::pair<const int, int>&) { return false; } };
+  const Pred pred; // erase_if parameter is passed by value, so non-const.
+  std::map<int, int> m;
+  std::erase_if(m, pred);
+  std::multimap<int, int> mm;
+  std::erase_if(mm, pred);
+}
+
 int
 main()
 {
   test01();
   test02();
+  test_pr107850();
 
   return 0;
 }