diff options
| author | Martin Hořeňovský | 2025-07-29 23:51:13 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2025-07-30 20:20:38 +0200 |
| commit | ccabd4de891e749f472121497941bb9437b83c2e (patch) | |
| tree | bed41bf34331cae112e53dba4104796324a92e7f /tests/SelfTest/UsageTests/Compilation.tests.cpp | |
| parent | a1c7ee115f17c1e83b382f33ef2614070974626f (diff) | |
| download | catch3-ccabd4de891e749f472121497941bb9437b83c2e.tar.gz | |
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
Diffstat (limited to 'tests/SelfTest/UsageTests/Compilation.tests.cpp')
| -rw-r--r-- | tests/SelfTest/UsageTests/Compilation.tests.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/SelfTest/UsageTests/Compilation.tests.cpp b/tests/SelfTest/UsageTests/Compilation.tests.cpp index 7a6a1f25..d8813353 100644 --- a/tests/SelfTest/UsageTests/Compilation.tests.cpp +++ b/tests/SelfTest/UsageTests/Compilation.tests.cpp @@ -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") { |