mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice
synced 2026-08-06 18:52:33 +00:00
test-display-base: Fix C++ designated initializer for anonymous union
C++ does not allow designated initializers to refer to members of
anonymous unions. The QXLInterface struct contains an anonymous union
with attached_worker/attache_worker, and the original code used
`{ .attached_worker = attached_worker }` which mixed a non-designated
clause (the outer braces without a field name) with designated clauses
for the other struct members, producing:
error: either all initializer clauses should be designated or none
of them should be
Simply removing the braces (`.attached_worker = attached_worker`) does
not help either, because C++ compilers do not recognize anonymous union
members as valid designators at the enclosing struct level.
Work around this by using an immediately-invoked lambda: the designated
initializer list skips the anonymous union (which gets zero-initialized),
and the lambda assigns `attached_worker` explicitly before returning
the fully initialized struct.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
e45861f995
commit
a68319bd34
@ -799,31 +799,35 @@ static void set_client_capabilities(QXLInstance *qin,
|
||||
}
|
||||
}
|
||||
|
||||
static QXLInterface display_sif = {
|
||||
.base = {
|
||||
.type = SPICE_INTERFACE_QXL,
|
||||
.description = "test",
|
||||
.major_version = SPICE_INTERFACE_QXL_MAJOR,
|
||||
.minor_version = SPICE_INTERFACE_QXL_MINOR
|
||||
},
|
||||
{ .attached_worker = attached_worker },
|
||||
.set_compression_level = set_compression_level,
|
||||
.set_mm_time = nullptr,
|
||||
.get_init_info = get_init_info,
|
||||
static QXLInterface display_sif = []() {
|
||||
QXLInterface sif = {
|
||||
.base = {
|
||||
.type = SPICE_INTERFACE_QXL,
|
||||
.description = "test",
|
||||
.major_version = SPICE_INTERFACE_QXL_MAJOR,
|
||||
.minor_version = SPICE_INTERFACE_QXL_MINOR
|
||||
},
|
||||
/* anonymous union member can't use designated initializer in C++ */
|
||||
.set_compression_level = set_compression_level,
|
||||
.set_mm_time = nullptr,
|
||||
.get_init_info = get_init_info,
|
||||
|
||||
/* the callbacks below are called from spice server thread context */
|
||||
.get_command = get_command,
|
||||
.req_cmd_notification = req_cmd_notification,
|
||||
.release_resource = release_resource,
|
||||
.get_cursor_command = get_cursor_command,
|
||||
.req_cursor_notification = req_cursor_notification,
|
||||
.notify_update = notify_update,
|
||||
.flush_resources = flush_resources,
|
||||
.async_complete = nullptr,
|
||||
.update_area_complete = nullptr,
|
||||
.set_client_capabilities = set_client_capabilities,
|
||||
.client_monitors_config = client_monitors_config,
|
||||
};
|
||||
/* the callbacks below are called from spice server thread context */
|
||||
.get_command = get_command,
|
||||
.req_cmd_notification = req_cmd_notification,
|
||||
.release_resource = release_resource,
|
||||
.get_cursor_command = get_cursor_command,
|
||||
.req_cursor_notification = req_cursor_notification,
|
||||
.notify_update = notify_update,
|
||||
.flush_resources = flush_resources,
|
||||
.async_complete = nullptr,
|
||||
.update_area_complete = nullptr,
|
||||
.set_client_capabilities = set_client_capabilities,
|
||||
.client_monitors_config = client_monitors_config,
|
||||
};
|
||||
sif.attached_worker = attached_worker;
|
||||
return sif;
|
||||
}();
|
||||
|
||||
/* interface for tests */
|
||||
void test_add_display_interface(Test* test)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user