Skip to content

Commit

Permalink
[libc++][test] Avoid MSVC constexpr bug
Browse files Browse the repository at this point in the history
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
  • Loading branch information
CaseyCarter committed Jan 10, 2023
1 parent a8d2219 commit 915f2f1
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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>);

Expand Down

0 comments on commit 915f2f1

Please sign in to comment.