Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/tests/SelfTest/UsageTests
diff options
context:
space:
mode:
authorMartin Hořeňovský2025-07-29 23:51:13 +0200
committerMartin Hořeňovský2025-07-30 20:20:38 +0200
commitccabd4de891e749f472121497941bb9437b83c2e (patch)
treebed41bf34331cae112e53dba4104796324a92e7f /tests/SelfTest/UsageTests
parenta1c7ee115f17c1e83b382f33ef2614070974626f (diff)
downloadcatch3-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')
-rw-r--r--tests/SelfTest/UsageTests/Compilation.tests.cpp17
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") {