[libcxx-commits] [libcxx] 915f2f1 - [libc++][test] Avoid MSVC constexpr bug
Casey Carter via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jan 9 17:48:15 PST 2023
Author: Casey Carter
Date: 2023-01-09T17:48:04-08:00
New Revision: 915f2f16fbb75793bfaface6efdce7ef31d2da52
URL: https://github.com/llvm/llvm-project/commit/915f2f16fbb75793bfaface6efdce7ef31d2da52
DIFF: https://github.com/llvm/llvm-project/commit/915f2f16fbb75793bfaface6efdce7ef31d2da52.diff
LOG: [libc++][test] Avoid MSVC constexpr bug
C++ constexpr allows a non-constant-expresssion lvalue to be used in a constant expression if it's not subject to lvalue-to-rvalue conversion. Subtly, this means you can make a constant-expression copy of a non-constant-expression object of empty type since the copy constructor doesn't perform lvalue-to-rvalue conversion. MSVC has had bugs with this usage forever, which will hopefully finally be mashed implementing C++23's relaxation on the use of pointers and references in constant expressions.
There's no need for this particular test to use this particular constexpr feature, we can simply make the predicates constant expressions.
Differential Revision: https://reviews.llvm.org/D141336
Added:
Modified:
libcxx/test/std/algorithms/ranges_robust_against_nonbool_predicates.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/test/std/algorithms/ranges_robust_against_nonbool_predicates.pass.cpp b/libcxx/test/std/algorithms/ranges_robust_against_nonbool_predicates.pass.cpp
index b69df4084052b..38457201acf70 100644
--- a/libcxx/test/std/algorithms/ranges_robust_against_nonbool_predicates.pass.cpp
+++ b/libcxx/test/std/algorithms/ranges_robust_against_nonbool_predicates.pass.cpp
@@ -23,11 +23,11 @@
#include "boolean_testable.h"
-auto unary_pred = [](int i) { return BooleanTestable(i > 0); };
+constexpr auto unary_pred = [](int i) { return BooleanTestable(i > 0); };
static_assert(!std::same_as<decltype(unary_pred(1)), bool>);
static_assert(std::convertible_to<decltype(unary_pred(1)), bool>);
-auto binary_pred = [](int i, int j) { return BooleanTestable(i < j); };
+constexpr auto binary_pred = [](int i, int j) { return BooleanTestable(i < j); };
static_assert(!std::same_as<decltype(binary_pred(1, 2)), bool>);
static_assert(std::convertible_to<decltype(binary_pred(1, 2)), bool>);
More information about the libcxx-commits
mailing list