-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Revert "Make STLExtras's (all|any|none)_of() Utility Functions Constexpr-Friendly" #173163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…xpr-Frie…" This reverts commit 21fd8cc.
|
@llvm/pr-subscribers-llvm-adt Author: Michał Górny (mgorny) ChangesReverts llvm/llvm-project#172536. This is causing weird assertion failures in clang, per #172536 (comment). It might be a bug in GCC, but still makes sense to revert it in the interest of bootstrapping. Full diff: https://github.com/llvm/llvm-project/pull/173163.diff 2 Files Affected:
diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index d4632ab72e563..409cd7b60fa00 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -638,10 +638,10 @@ make_early_inc_range(RangeT &&Range) {
// Forward declarations required by zip_shortest/zip_equal/zip_first/zip_longest
template <typename R, typename UnaryPredicate>
-constexpr bool all_of(R &&range, UnaryPredicate P);
+bool all_of(R &&range, UnaryPredicate P);
template <typename R, typename UnaryPredicate>
-constexpr bool any_of(R &&range, UnaryPredicate P);
+bool any_of(R &&range, UnaryPredicate P);
template <typename T> bool all_equal(std::initializer_list<T> Values);
@@ -1734,31 +1734,22 @@ UnaryFunction for_each(R &&Range, UnaryFunction F) {
/// Provide wrappers to std::all_of which take ranges instead of having to pass
/// begin/end explicitly.
template <typename R, typename UnaryPredicate>
-constexpr bool all_of(R &&Range, UnaryPredicate P) {
- // TODO: switch back to std::all_of() after it becomes constexpr in c++20.
- for (auto I = adl_begin(Range), E = adl_end(Range); I != E; ++I)
- if (!P(*I))
- return false;
- return true;
+bool all_of(R &&Range, UnaryPredicate P) {
+ return std::all_of(adl_begin(Range), adl_end(Range), P);
}
/// Provide wrappers to std::any_of which take ranges instead of having to pass
/// begin/end explicitly.
template <typename R, typename UnaryPredicate>
-constexpr bool any_of(R &&Range, UnaryPredicate P) {
- // TODO: switch back to std::any_of() after it becomes constexpr in c++20.
- for (auto I = adl_begin(Range), E = adl_end(Range); I != E; ++I)
- if (P(*I))
- return true;
- return false;
+bool any_of(R &&Range, UnaryPredicate P) {
+ return std::any_of(adl_begin(Range), adl_end(Range), P);
}
/// Provide wrappers to std::none_of which take ranges instead of having to pass
/// begin/end explicitly.
template <typename R, typename UnaryPredicate>
-constexpr bool none_of(R &&Range, UnaryPredicate P) {
- // TODO: switch back to std::none_of() after it becomes constexpr in c++20.
- return !any_of(Range, P);
+bool none_of(R &&Range, UnaryPredicate P) {
+ return std::none_of(adl_begin(Range), adl_end(Range), P);
}
/// Provide wrappers to std::fill which take ranges instead of having to pass
diff --git a/llvm/unittests/ADT/STLExtrasTest.cpp b/llvm/unittests/ADT/STLExtrasTest.cpp
index da84345eecda8..dbf439b8d63a0 100644
--- a/llvm/unittests/ADT/STLExtrasTest.cpp
+++ b/llvm/unittests/ADT/STLExtrasTest.cpp
@@ -1260,25 +1260,6 @@ TEST(STLExtras, MoveRange) {
EXPECT_TRUE(llvm::all_of(V4, HasVal));
}
-TEST(STLExtrasTest, AllOfAnyOfNoneOfConstexpr) {
- // Verify constexpr evaluation works. Functional correctness is tested in
- // runtime tests (e.g., MoveRange).
- constexpr std::array<int, 3> Arr = {1, 2, 3};
- static_assert(all_of(Arr, [](int X) { return X > 0; }));
- static_assert(any_of(Arr, [](int X) { return X == 2; }));
- static_assert(none_of(Arr, [](int X) { return X < 0; }));
-
- // Verify constexpr works with C-style arrays.
- constexpr int CArr[] = {1, 2};
- static_assert(all_of(CArr, [](int X) { return X > 0; }));
-
- // Verify empty range edge case.
- constexpr std::array<int, 0> Empty = {};
- static_assert(all_of(Empty, [](int) { return false; }));
- static_assert(!any_of(Empty, [](int) { return true; }));
- static_assert(none_of(Empty, [](int) { return true; }));
-}
-
TEST(STLExtras, Unique) {
std::vector<int> V = {1, 5, 5, 4, 3, 3, 3};
|
🪟 Windows x64 Test Results
✅ The build succeeded and all tests passed. |
🐧 Linux x64 Test Results
✅ The build succeeded and all tests passed. |
This reverts commit a71b1d2.
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
Signed-off-by: Michał Górny <mgorny@gentoo.org>
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/27/builds/20615 Here is the relevant piece of the build log for the reference |
Reverts #172536. This is causing weird assertion failures in clang, per #172536 (comment). It might be a bug in GCC, but still makes sense to revert it in the interest of bootstrapping.