diff --git a/dds/idl/dds_generator.h b/dds/idl/dds_generator.h index d2e83f2ef98..e6ca05b9a09 100644 --- a/dds/idl/dds_generator.h +++ b/dds/idl/dds_generator.h @@ -1459,6 +1459,11 @@ bool has_discriminator(AST_Union* u, FieldFilter filter_kind) || filter_kind == FieldFilter_All; } +// TODO: Add more fine-grained control of "const" string for the wrapper type and wrapped type. +// Currently, there is a single bool to control both; that is, either both are "const" or +// none is "const". But sometimes, we want something like "const KeyOnly&", and +// not "const KeyOnly&" or "KeyOnly&". + /// Handling wrapping and unwrapping references in the wrapper types: /// NestedKeyOnly, KeyOnly, IDL::DistinctType, and *_forany. struct RefWrapper { @@ -1720,7 +1725,8 @@ std::string key_only_type_name(AST_Type* type, const std::string& type_name, { RefWrapper wrapper(type, type_name, "", writing ? true : false); wrapper.field_filter_ = field_filter; - return wrapper.done().wrapped_type_name(); + const bool has_wrapper = field_filter != FieldFilter_All; + return (has_wrapper && !writing ? "const " : "") + wrapper.done().wrapped_type_name(); } #endif diff --git a/docs/news.d/keyonly_vread_vwrite.rst b/docs/news.d/keyonly_vread_vwrite.rst index e4c449ccf2a..774438d6ede 100644 --- a/docs/news.d/keyonly_vread_vwrite.rst +++ b/docs/news.d/keyonly_vread_vwrite.rst @@ -1,5 +1,5 @@ .. news-prs: 4554 .. news-start-section: Fixes -- KeyOnly serialization of union that has no key now has a delimiter for appendable and mutable extensibility. +- XCDR2 KeyOnly serialization of union that has no key now has a delimiter for appendable and mutable extensibility. .. news-end-section