From 5457803a6f95d8c6f7b9da46326c7f99b8514bb9 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Mon, 24 Nov 2025 00:30:08 -0600 Subject: [PATCH 1/3] generate enum traits as `constexpr` --- Enum.pm | 10 +++++----- changelog.txt | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Enum.pm b/Enum.pm index 777b6ae7a..8d3ea500c 100644 --- a/Enum.pm +++ b/Enum.pm @@ -154,18 +154,18 @@ sub render_enum_tables($$$$$$) { with_emit_traits { emit_block { - emit "static const bool is_complex = " . ($complex ? 'true' : 'false') . ";"; + emit "static constexpr bool is_complex = " . ($complex ? 'true' : 'false') . ";"; emit "typedef $base_type base_type;"; emit "typedef $full_name enum_type;"; - emit "static const base_type first_item_value = $base;"; - emit "static const base_type last_item_value = $last_value;"; + emit "static constexpr base_type first_item_value = $base;"; + emit "static constexpr base_type last_item_value = $last_value;"; # Cast the enum to integer in order to avoid GCC <= 4.5 assuming the value range is correct. emit_block { emit "return (value >= first_item_value && ", "value <= last_item_value);"; } "static inline bool is_valid(base_type value) "; - emit "static const enum_type first_item = (enum_type)first_item_value;"; - emit "static const enum_type last_item = (enum_type)last_item_value;"; + emit "static constexpr enum_type first_item = (enum_type)first_item_value;"; + emit "static constexpr enum_type last_item = (enum_type)last_item_value;"; emit "static const char *const key_table[", $count, "];"; if ($complex) { emit "static const DFHack::enum_identity::ComplexData complex;"; diff --git a/changelog.txt b/changelog.txt index b9ce525b0..1e710d5da 100644 --- a/changelog.txt +++ b/changelog.txt @@ -18,6 +18,9 @@ Template for new versions: # Future +## Structures +- updated codegen to generate enum trait constants as ``consteval`` + ## Structures # 53.04-r1 From cc8bbcfe7e1d9a04e195a2420580979a70f1dc47 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Mon, 24 Nov 2025 19:20:24 -0600 Subject: [PATCH 2/3] fix typo --- changelog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index 7b5aead30..3d06302bb 100644 --- a/changelog.txt +++ b/changelog.txt @@ -19,7 +19,7 @@ Template for new versions: # Future ## Structures -- updated codegen to generate enum trait constants as ``consteval`` +- updated codegen to generate enum trait constants as ``constexpr`` ## Structures From 22416ccafbb1ee8e6204beea786d860b3664a14d Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Mon, 24 Nov 2025 19:22:21 -0600 Subject: [PATCH 3/3] use `using` instead of `typedef` might as well fix that while we're here --- Enum.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Enum.pm b/Enum.pm index 8d3ea500c..7058f8c35 100644 --- a/Enum.pm +++ b/Enum.pm @@ -155,8 +155,8 @@ sub render_enum_tables($$$$$$) { with_emit_traits { emit_block { emit "static constexpr bool is_complex = " . ($complex ? 'true' : 'false') . ";"; - emit "typedef $base_type base_type;"; - emit "typedef $full_name enum_type;"; + emit "using base_type = $base_type;"; + emit "using enum_type = $full_name;"; emit "static constexpr base_type first_item_value = $base;"; emit "static constexpr base_type last_item_value = $last_value;"; # Cast the enum to integer in order to avoid GCC <= 4.5 assuming the value range is correct.