From d930c74c4d8211d551d0cb99054f13338113f4f9 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 13 Aug 2026 12:30:56 -0700 Subject: [PATCH] libghostty: make sized initialization valid C++ Use an immediately invoked lambda for GHOSTTY_INIT_SIZED in C++ so the macro value-initializes every field before setting the ABI size. The previous C compound literal and designated initializer required compiler extensions in C++17 and C++20. Keep the existing standard compound literal for C callers. --- include/ghostty/vt/types.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/ghostty/vt/types.h b/include/ghostty/vt/types.h index bd3d37d65..c66ee89d2 100644 --- a/include/ghostty/vt/types.h +++ b/include/ghostty/vt/types.h @@ -319,8 +319,17 @@ typedef struct { * opts.trim = true; * @endcode */ +#ifdef __cplusplus +#define GHOSTTY_INIT_SIZED(type) \ + ([]() noexcept { \ + type value{}; \ + value.size = sizeof(value); \ + return value; \ + }()) +#else #define GHOSTTY_INIT_SIZED(type) \ ((type){ .size = sizeof(type) }) +#endif /** * Return a pointer to a null-terminated JSON string describing the