From b4bb1b103fc3acbcafcb6acc0e6b1cdd15a07cbb Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Wed, 29 Mar 2017 11:51:20 -0700 Subject: [PATCH] Fix flatc code gen. Mutable functions should return a non-const reference to the member variable. Change-Id: I833077d2c9a38a5d71868e43aca6b250d79b6625 --- src/idl_gen_cpp.cpp | 2 ++ tests/monster_test.bfbs | Bin 4192 -> 4176 bytes tests/monster_test_generated.h | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index 0e8bb28de..8977c6b0f 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -1928,6 +1928,8 @@ class CppGenerator : public BaseGenerator { code_ += " }"; if (parser_.opts.mutable_buffer) { + auto mut_field_type = GenTypeGet(field.value.type, " ", "", " &", true); + code_.SetValue("FIELD_TYPE", mut_field_type); if (is_scalar) { code_.SetValue("ARG", GenTypeBasic(field.value.type, true)); code_.SetValue("FIELD_VALUE", diff --git a/tests/monster_test.bfbs b/tests/monster_test.bfbs index a27bafc6170dc9a38ad5c273106f5316f28135ce..d5a1aadaa8f75c7ae65abe98251ea9906c6650cc 100644 GIT binary patch literal 4176 zcmai1PiPcZ82>hj`DaXGOf`*GMv)*QizY!tio_J71&zg|Y3U_Qc4ys{*_mZ`HZ`S4 zPoan6p@{S#;;DG@RC*{yLMb9W^iYa;=%IM6QU$k#^~lUg^h7@Dv#Zje$;rt~UwRMec1Bxs37iPLZo%ythf@ zlP-~{N90>jGk6YwMl&K$K`j`cJ~Ig&X003s&@rI8+AyLfKG8Dl_kgJPO;8``^uh_Z z>}8K%aLX0n%N`3BjLaphT?M@lqOCiBi(_=qXxa~P9P|Azu#q;|whaR#b2gDVJbO9} zYLQpPN~gx53)aCsmHQmN!QDn9e%h-=QzhCn?auk$d!?v&JgAqk(g{opqG<5+rwEIz zQEix8T|X_yF=IoTJTrM5ot%Qr#Owvx7|@4RF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PN-g|T7{BFe#-m~{9X8>F!?WN ze!91u>zQD_<{<7XeU4d;hwgKoP_YeLJYk<>ZN+0r%T#wd^O=t>ZT8^~WQ{n}-;DBC z-+%Bo&AKbQbGX1fe_q+b@3%M}xS%iwA%#5`BgHS1SFkt;qCIge>6o^U9Xq4!xvK3~?@Q4yqe3bu$BodIv_T?^2O}F&sdn7nW)0levihmd#Ww&Z z_5Icct=q6BKkX@il4GOl)zZOwFV%RGyeFFTk%Bczc~_Idu)Yw}?Lx~qA0c^7!fr>%?|<#6zv`|p5`g4TnK`+XW8Byt)u>9ZN1Hm$2u*Ga== zu`Xhd{+PTu&D%|#bNo0$Oa>v7`Q=@_GIWj7N>hffW%M(y<$}n|s&7e(J}|2Ei}k>n zgM2(Ifm(dK9GFG#Vbx4PPO62z`&wUyG7DvVx43!Kz>3}2js|Nwwp&uB-8;3Nnb__& z)mtPr1{CdPUMx^-H{-#aoB{0sF=^jmx(RBLqf<_PRGvad2W&HY#1*Y;RSz14oE-KU zVUvGJ^Dn>u>_Pn0Ig9;vSZey#srma@1LWm9c^P}H>SaXp_Ob@w1bvF0k< zsu@H64+E33Zx;A0G_uxLk3O8}_lWq|CU*Ob@-y!H(!p5U@Fw}siy7g!JF#YNu%-SJ ntj^0wZuw6Ikja1Kj1FaCsCTTDJk~%Y&-m~5n%k)3k0Hjt+xf|! diff --git a/tests/monster_test_generated.h b/tests/monster_test_generated.h index b1fac7463..57966f5fc 100644 --- a/tests/monster_test_generated.h +++ b/tests/monster_test_generated.h @@ -243,7 +243,7 @@ MANUALLY_ALIGNED_STRUCT(16) Vec3 FLATBUFFERS_FINAL_CLASS { const Test &test3() const { return test3_; } - const Test &mutable_test3() { + Test &mutable_test3() { return test3_; } };