Add enum types to what is captured by value by default

As it turns out, enums can be used to declare bitfields, and we
cannot form a reference to a bitfield in the cpature. Thus, we add
`std::is_enum` as a criteria to the default for `capture_by_value`,
so that enum-based bitfields are also captured by value and thus
decomposable.

Closes #3001
This commit is contained in:
Martin Hořeňovský
2025-07-29 23:51:13 +02:00
parent a1c7ee115f
commit ccabd4de89
20 changed files with 164 additions and 29 deletions

View File

@@ -144,6 +144,23 @@ TEST_CASE("#1027: Bitfields can be captured") {
REQUIRE(0 == y.v);
}
TEST_CASE( "#3001: Enum-based bitfields can be captured" ) {
enum E {
ZERO = 0,
ONE = 1,
TWO = 2,
};
struct BF {
E e : 2;
};
BF bf{};
bf.e = ONE;
REQUIRE( bf.e == 1 );
REQUIRE( 1 == bf.e );
}
// Comparison operators can return non-booleans.
// This is unusual, but should be supported.
TEST_CASE("#1147") {