From 3f465062a0d60c0346c3d2a780f858ba8bfa7634 Mon Sep 17 00:00:00 2001 From: Tristan Honscheid Date: Tue, 11 Mar 2025 14:28:32 -0600 Subject: [PATCH 1/2] device: Update SYS_INIT_NAMED() to be C++ compatible In #84394, `struct init_entry` was modified to remove an unneeded union. The `SYS_INIT_NAMED()` macro was adjusted accordingly, but is no longer C++ compatible due to the partial designated initializer. Add an explicit value (NULL) for the other field (`dev`) in that struct. Signed-off-by: Tristan Honscheid --- include/zephyr/init.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/zephyr/init.h b/include/zephyr/init.h index 8d476e1a6456..c9526976dd88 100644 --- a/include/zephyr/init.h +++ b/include/zephyr/init.h @@ -166,7 +166,7 @@ struct init_entry { #define SYS_INIT_NAMED(name, init_fn_, level, prio) \ static const Z_DECL_ALIGN(struct init_entry) \ Z_INIT_ENTRY_SECTION(level, prio, 0) __used __noasan \ - Z_INIT_ENTRY_NAME(name) = {.init_fn = (init_fn_)} \ + Z_INIT_ENTRY_NAME(name) = {.init_fn = (init_fn_), .dev = NULL} \ /** @} */ From e3f290fd46e14e317f18e81a4696d6bfc419d5a6 Mon Sep 17 00:00:00 2001 From: Tristan Honscheid Date: Wed, 12 Mar 2025 10:41:22 -0600 Subject: [PATCH 2/2] device: Update Z_DEVICE_INIT_ENTRY_DEFINE to be C++ compatible The `Z_DEVICE_INIT_ENTRY_DEFINE()` macro uses a designated initializer to define a struct. Ensure all members of `struct init_entry` are defined in order for C++ compatibility. Signed-off-by: Tristan Honscheid --- include/zephyr/device.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/zephyr/device.h b/include/zephyr/device.h index 7cd17ac41e7c..ef01ea323f1b 100644 --- a/include/zephyr/device.h +++ b/include/zephyr/device.h @@ -1241,7 +1241,8 @@ device_get_dt_nodelabels(const struct device *dev) static const Z_DECL_ALIGN(struct init_entry) __used __noasan Z_INIT_ENTRY_SECTION( \ level, prio, Z_DEVICE_INIT_SUB_PRIO(node_id)) \ Z_INIT_ENTRY_NAME(DEVICE_NAME_GET(dev_id)) = { \ - .dev = (const struct device *)&DEVICE_NAME_GET(dev_id) \ + .init_fn = NULL, \ + .dev = (const struct device *)&DEVICE_NAME_GET(dev_id), \ } /**