Skip to content

add deduction guides for Struct from std::tuple (Fix for C++23 on gcc 15)#525

Merged
sangelovic merged 2 commits intoKistler-Group:masterfrom
heinemml:fix_tuple_for_cpp23
Jan 15, 2026
Merged

add deduction guides for Struct from std::tuple (Fix for C++23 on gcc 15)#525
sangelovic merged 2 commits intoKistler-Group:masterfrom
heinemml:fix_tuple_for_cpp23

Conversation

@heinemml
Copy link
Contributor

C++23 changed the generation of implicit deduction guides. This causes the compiler to also see deduction guides for std::tuple as candidates for sdbus::Struct.
Because of the competing guides the compiler doesn't know which one to pick.

This seems to be implemented from gcc 15 on and is thus causing breakage there.

To fix this we need to add explicit deduction guides when std::tuple is passed to sdbus::Struct.

fixes #524

C++23 changed the generation of implicit deduction guides. This causes
the compiler to also see deduction guides for std::tuple as candidates
for sdbus::Struct.
Because of the competing guides the compiler doesn't know which one to pick.

This seems to be implemented from gcc 15 on and is thus causing breakage there.

To fix this we need to add explicit deduction guides when std::tuple is passed
to sdbus::Struct.

fixes Kistler-Group#524
@heinemml heinemml changed the title Types.h: add deduction guides for Struct from std::tuple (Fix for C++23 on gcc 15) add deduction guides for Struct from std::tuple (Fix for C++23 on gcc 15) Jan 14, 2026
@sangelovic
Copy link
Collaborator

sangelovic commented Jan 15, 2026

@heinemml Thanks for reporting the issue and the PR. I'm fine with that except of a little detail -- we need to remove std::decay_t<> wrapper from the deduction guides. Keeping it would induce an unnecessary performance inefficiency on serialization implementation in SDBUSCPP_REGISTER_STRUCT macro, and would completely break deserialization implementation in that macro. The mechanism in those implementations is built on std::forward_as_tuple which creates a tuple of references, and hence we need to also create the same Struct with its element types being references. The result is an thin, "observer" struct which merely points to items in the user-defined struct, bringing the convenience of avoiding copies in serialization and making the deserialization happen through Struct instance into the destination user-defined struct. I can to the correction myself, or will you?

We need to be able to create sdbus::Structs
with element types being references.
@sangelovic
Copy link
Collaborator

I already did it.

@sangelovic
Copy link
Collaborator

Unit tests would have failed on the original std::decay_t-based solution -- a symptom of broken user-defined struct deserialization:

1: [ RUN      ] AMessage.CanCarryUserDefinedStruct
1: /home/projects/Kistler-Group/sdbus-cpp/tests/unittests/Message_test.cpp:535: Failure
1: Value of: dataRead
1: Expected: is equal to 72-byte object <FE-18 36-00 00-00 00-00 30-1A B1-9F 99-55 00-00 05-00 00-00 00-00 00-00 68-65 6C-6C 6F-00 00-00 02-00 00-00 00-00 00-00 60-2A B1-9F 99-55 00-00 90-D9 B0-9F 99-55 00-00 02-00 00-00 00-00 00-00 01-00 00-00 65-2F 6F-62>
1:   Actual: 72-byte object <00-00 00-00 00-00 00-00 78-8C E1-30 FC-7F 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 88-8C E1-30 FC-7F 00-00 88-8C E1-30 FC-7F 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00> (of type my::Struct)
1: 
1: [  FAILED  ] AMessage.CanCarryUserDefinedStruct (0 ms)

@sangelovic sangelovic merged commit 6f694e3 into Kistler-Group:master Jan 15, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SDBUSCPP_REGISTER_STRUCT not working with gcc-15 and C++23

2 participants