From 151ebc8a2925bca5210ac447156a6a783f1d9337 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 19 Apr 2019 16:19:57 -0700 Subject: [PATCH] Fixed oneof case accessor to cast to enum for C++. --- BUILD | 1 + tests/json/test.proto | 5 +++++ tests/json/test.proto.pb | Bin 1883 -> 1958 bytes tests/json/test_json.cc | 1 + upbc/generator.cc | 2 +- 5 files changed, 8 insertions(+), 1 deletion(-) diff --git a/BUILD b/BUILD index b54e0bed39..c700832614 100644 --- a/BUILD +++ b/BUILD @@ -326,6 +326,7 @@ cc_test( ], deps = [ ":test_json_upbprotoreflection", + ":test_json_upbproto", ":upb_json", ":upb_test", ], diff --git a/tests/json/test.proto b/tests/json/test.proto index e6590011da..2db0388d77 100644 --- a/tests/json/test.proto +++ b/tests/json/test.proto @@ -29,6 +29,11 @@ message TestMessage { map map_string_int32 = 23; map map_string_bool = 24; map map_string_msg = 25; + + oneof o { + int32 oneof_int32 = 26; + int64 oneof_int64 = 27; + } } message SubMessage { diff --git a/tests/json/test.proto.pb b/tests/json/test.proto.pb index 5da355d6003740d69f99d5a55257df39e4816090..94b8b92e61664fd0d5d9ddef9b2c88668a7fb951 100644 GIT binary patch delta 104 zcmcc3w~U{eYcc;sW_6~`d>eJ_Slxsaxw!N5QuEW|GxJJ}jU=QL7&TZu7=pOKf}S8T h6eVUR64F2=%*aa2Og3k+u3}_$V&-DZpDe=e4gjs=8$$p9 delta 27 jcmZ3+f18h)>jvLMW_6|)yc>1wST}EAUBx&#p4}Y)ds_&% diff --git a/tests/json/test_json.cc b/tests/json/test_json.cc index 3fddfb6174..66508179b3 100644 --- a/tests/json/test_json.cc +++ b/tests/json/test_json.cc @@ -4,6 +4,7 @@ */ #include "tests/json/test.upbdefs.h" +#include "tests/json/test.upb.h" // Test that it compiles for C++. #include "tests/test_util.h" #include "tests/upb_test.h" #include "upb/handlers.h" diff --git a/upbc/generator.cc b/upbc/generator.cc index 27600693da..5843597527 100644 --- a/upbc/generator.cc +++ b/upbc/generator.cc @@ -362,7 +362,7 @@ void GenerateMessageInHeader(const protobuf::Descriptor* message, Output& output fullname); output( "UPB_INLINE $0_oneofcases $1_$2_case(const $1* msg) { " - "return UPB_FIELD_AT(msg, int, $3); }\n" + "return ($0_oneofcases)UPB_FIELD_AT(msg, int32_t, $3); }\n" "\n", fullname, msgname, oneof->name(), GetSizeInit(layout.GetOneofCaseOffset(oneof)));