Browse Source

Fixes bug with vector<bool> in generate_class.py

Caleb Fangmeier 6 years ago
parent
commit
c0b4e453a2
1 changed files with 3 additions and 1 deletions
  1. 3 1
      tools/generate_class.py

+ 3 - 1
tools/generate_class.py

@@ -63,8 +63,10 @@ struct {obj_name} {{
     for field in obj_attrs['fields']:
         name = field['name']
         type_ = field['type']
+        # Because vector<bool> is packed, a temporary object is created so we can't return a reference.
+        ret_type = f'{type_}&' if type_ != 'bool' else type_
         src.append(f'''\
-    const {type_}& {name}() const {{
+    const {ret_type} {name}() const {{
         if (!collection->{name}_loaded) {{
             collection->val_{name} = collection->tds->track_branch_obj<vector<{type_}>>("{prefix}_{name}");
             collection->{name}_loaded = true;