| Index: mojo/public/tools/bindings/generators/cpp_templates/struct_traits_declaration.tmpl
|
| diff --git a/mojo/public/tools/bindings/generators/cpp_templates/struct_traits_declaration.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/struct_traits_declaration.tmpl
|
| index 24efbd5531064d623c8922793359cd78f98022ac..1b7cf8954ba9c66719d73d8a05a99d3cbdfa30f6 100644
|
| --- a/mojo/public/tools/bindings/generators/cpp_templates/struct_traits_declaration.tmpl
|
| +++ b/mojo/public/tools/bindings/generators/cpp_templates/struct_traits_declaration.tmpl
|
| @@ -8,10 +8,16 @@ struct {{export_attribute}} StructTraits<{{mojom_type}}::DataView,
|
|
|
| {%- for field in struct.fields %}
|
| {%- set return_ref = field.kind|is_object_kind or
|
| - field.kind|is_any_handle_or_interface_kind %}
|
| + field.kind|is_any_handle_or_interface_kind %}
|
| +{# We want the field accessor to be const whenever possible to allow
|
| + structs to be used as map keys.
|
| + TODO(tibell): Make this check more precise to deal with e.g.
|
| + custom types which don't contain handles but require non-const
|
| + reference for serialization. #}
|
| +{%- set maybe_const = "" if field.kind|contains_handles_or_interfaces else "const" %}
|
| {%- if return_ref %}
|
| - static decltype({{mojom_type}}::{{field.name}})& {{field.name}}(
|
| - {{mojom_type}}Ptr& input) {
|
| + static {{maybe_const}} decltype({{mojom_type}}::{{field.name}})& {{field.name}}(
|
| + {{maybe_const}} {{mojom_type}}Ptr& input) {
|
| return input->{{field.name}};
|
| }
|
| {%- else %}
|
|
|