mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-02 21:35:40 +02:00
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:
@@ -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") {
|
||||
|
Reference in New Issue
Block a user