Skip to content

Conversation

@elhewaty
Copy link
Member

Fixes #118355

@elhewaty elhewaty requested a review from a team as a code owner February 22, 2025 14:53
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Feb 22, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 22, 2025

@llvm/pr-subscribers-libcxx

Author: None (elhewaty)

Changes

Fixes #118355


Full diff: https://github.com/llvm/llvm-project/pull/128358.diff

5 Files Affected:

  • (modified) libcxx/docs/Status/Cxx2cIssues.csv (+1-1)
  • (modified) libcxx/include/forward_list (+1-1)
  • (modified) libcxx/include/list (+1-1)
  • (added) libcxx/test/libcxx/containers/sequences/forwardlist/bool-conversion.pass.cpp (+28)
  • (added) libcxx/test/libcxx/containers/sequences/list/list.modifiers/bool-conversion.pass.cpp (+28)
diff --git a/libcxx/docs/Status/Cxx2cIssues.csv b/libcxx/docs/Status/Cxx2cIssues.csv
index 1ec23dfabd5ea..228d95dead807 100644
--- a/libcxx/docs/Status/Cxx2cIssues.csv
+++ b/libcxx/docs/Status/Cxx2cIssues.csv
@@ -97,7 +97,7 @@
 "`LWG4124 <https://wg21.link/LWG4124>`__","Cannot format ``zoned_time`` with resolution coarser than ``seconds``","2024-11 (Wrocław)","","",""
 "`LWG4126 <https://wg21.link/LWG4126>`__","Some feature-test macros for fully freestanding features are not yet marked freestanding","2024-11 (Wrocław)","","",""
 "`LWG4134 <https://wg21.link/LWG4134>`__","Issue with Philox algorithm specification","2024-11 (Wrocław)","","",""
-"`LWG4135 <https://wg21.link/LWG4135>`__","The helper lambda of ``std::erase`` for list should specify return type as ``bool``","2024-11 (Wrocław)","","",""
+"`LWG4135 <https://wg21.link/LWG4135>`__","The helper lambda of ``std::erase`` for list should specify return type as ``bool``","2024-11 (Wrocław)","|Complete|","21",""
 "`LWG4140 <https://wg21.link/LWG4140>`__","Useless default constructors for bit reference types","2024-11 (Wrocław)","","",""
 "`LWG4141 <https://wg21.link/LWG4141>`__","Improve prohibitions on ""additional storage""","2024-11 (Wrocław)","","",""
 "`LWG4142 <https://wg21.link/LWG4142>`__","``format_parse_context::check_dynamic_spec`` should require at least one type","2024-11 (Wrocław)","","",""
diff --git a/libcxx/include/forward_list b/libcxx/include/forward_list
index 4b6ca8ea8587c..8c688611d5ee2 100644
--- a/libcxx/include/forward_list
+++ b/libcxx/include/forward_list
@@ -1557,7 +1557,7 @@ erase_if(forward_list<_Tp, _Allocator>& __c, _Predicate __pred) {
 template <class _Tp, class _Allocator, class _Up>
 inline _LIBCPP_HIDE_FROM_ABI typename forward_list<_Tp, _Allocator>::size_type
 erase(forward_list<_Tp, _Allocator>& __c, const _Up& __v) {
-  return std::erase_if(__c, [&](auto& __elem) { return __elem == __v; });
+  return std::erase_if(__c, [&](const auto& __elem) -> bool { return __elem == __v; });
 }
 #  endif
 
diff --git a/libcxx/include/list b/libcxx/include/list
index 3fcf796ebc03d..1285174f1c384 100644
--- a/libcxx/include/list
+++ b/libcxx/include/list
@@ -1703,7 +1703,7 @@ erase_if(list<_Tp, _Allocator>& __c, _Predicate __pred) {
 template <class _Tp, class _Allocator, class _Up>
 inline _LIBCPP_HIDE_FROM_ABI typename list<_Tp, _Allocator>::size_type
 erase(list<_Tp, _Allocator>& __c, const _Up& __v) {
-  return std::erase_if(__c, [&](auto& __elem) { return __elem == __v; });
+  return std::erase_if(__c, [&](const auto& __elem) -> bool { return __elem == __v; });
 }
 
 template <>
diff --git a/libcxx/test/libcxx/containers/sequences/forwardlist/bool-conversion.pass.cpp b/libcxx/test/libcxx/containers/sequences/forwardlist/bool-conversion.pass.cpp
new file mode 100644
index 0000000000000..402ea1e2b1880
--- /dev/null
+++ b/libcxx/test/libcxx/containers/sequences/forwardlist/bool-conversion.pass.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <forward_list>
+
+#include <forward_list>
+struct Bool {
+  Bool() = default;
+  Bool(const Bool&) = delete;
+  operator bool() const { return true; }
+};
+
+struct Int {
+  Bool& operator==(Int) const {
+    static Bool b;
+    return b;
+  }
+};
+
+int main() {
+  std::forward_list<Int> l;
+  std::erase(l, Int{});
+}
diff --git a/libcxx/test/libcxx/containers/sequences/list/list.modifiers/bool-conversion.pass.cpp b/libcxx/test/libcxx/containers/sequences/list/list.modifiers/bool-conversion.pass.cpp
new file mode 100644
index 0000000000000..eb26e9e700f68
--- /dev/null
+++ b/libcxx/test/libcxx/containers/sequences/list/list.modifiers/bool-conversion.pass.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <list>
+
+#include <list>
+struct Bool {
+  Bool() = default;
+  Bool(const Bool&) = delete;
+  operator bool() const { return true; }
+};
+
+struct Int {
+  Bool& operator==(Int) const {
+    static Bool b;
+    return b;
+  }
+};
+
+int main() {
+  std::list<Int> l;
+  std::erase(l, Int{});
+}

@github-actions
Copy link

github-actions bot commented Feb 22, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@mordante mordante self-assigned this Feb 22, 2025
Copy link
Member

@mordante mordante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This almost ready to go, it needs a few changes to the test.

Copy link
Member

@mordante mordante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor thing and then it's great.

Copy link
Member

@mordante mordante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LGTM!

@mordante mordante added the pending-ci Merging the PR is only pending completion of CI label Feb 25, 2025
@elhewaty elhewaty merged commit 2c36411 into llvm:main Feb 26, 2025
86 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. pending-ci Merging the PR is only pending completion of CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LWG4135: The helper lambda of std::erase for list should specify return type as bool

4 participants