interrogate: generated property getter should copy in some cases

This is to fix eg. public ButtonHandle members from being returned as const reference, which means they won't outlive the struct they are accessed on, a recipe for obscure crashes.

The is_trivial() criterium for this to apply is admittedly really arbitrary; I haven't really figured out what the right criterium should be, but it's better than hardcoding ButtonHandle.
This commit is contained in:
rdb 2018-10-29 22:39:17 +01:00 committed by Sam Edwards
parent 2ed4cd7ce6
commit ad3b145951

View File

@ -1389,7 +1389,8 @@ scan_element(CPPInstance *element, CPPStructType *struct_type,
// We can only generate a getter and a setter if we can talk about the
// type it is.
if (parameter_type->as_struct_type() != nullptr) {
if (parameter_type->as_struct_type() != nullptr &&
!parameter_type->is_trivial()) {
// Wrap the type in a const reference.
parameter_type = TypeManager::wrap_const_reference(parameter_type);
}