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.
This commit is contained in:
Mitchell Hashimoto
2026-08-13 12:30:56 -07:00
parent 309440e07f
commit d930c74c4d

View File

@@ -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