forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libcxx] Add LWG4135: The helper lambda of std::erase for list should…
… specify return type as bool (llvm#128358) Fixes llvm#118355
- Loading branch information
Showing
5 changed files
with
77 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
libcxx/test/libcxx/containers/sequences/forwardlist/bool-conversion.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// REQUIRES: std-at-least-c++20 | ||
|
||
// <forward_list> | ||
|
||
// This test shows the effect of implementing `LWG4135`, before it this code | ||
// was ill-formed, as the predicate is not bool. `LWG4135` suggests that | ||
// std::erase explicitly specifying the lambda's return type as bool. | ||
|
||
#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(int, char**) { | ||
std::forward_list<Int> l; | ||
std::erase(l, Int{}); | ||
|
||
return 0; | ||
} |
37 changes: 37 additions & 0 deletions
37
libcxx/test/libcxx/containers/sequences/list/list.modifiers/bool-conversion.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// REQUIRES: std-at-least-c++20 | ||
|
||
// <list> | ||
|
||
// This test shows the effect of implementing `LWG4135`, before it this code | ||
// was ill-formed, as the predicate is not bool. `LWG4135` suggests that | ||
// std::erase explicitly specifying the lambda's return type as bool. | ||
|
||
#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(int, char**) { | ||
std::list<Int> l; | ||
std::erase(l, Int{}); | ||
|
||
return 0; | ||
} |