From fd0d1ed9298d4f495492bfea7e58935d52489bd5 Mon Sep 17 00:00:00 2001 From: Derek Bailey Date: Wed, 2 Feb 2022 22:29:21 -0800 Subject: [PATCH] update C++ generator to emit scoped enums in vector of unions (#7075) --- include/flatbuffers/idl.h | 4 ++++ src/idl_gen_cpp.cpp | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h index 039e3c5d4..0b11ba451 100644 --- a/include/flatbuffers/idl.h +++ b/include/flatbuffers/idl.h @@ -468,6 +468,10 @@ inline bool IsUnion(const Type &type) { return type.enum_def != nullptr && type.enum_def->is_union; } +inline bool IsUnionType(const Type &type) { + return IsUnion(type) && IsInteger(type.base_type); +} + inline bool IsVector(const Type &type) { return type.base_type == BASE_TYPE_VECTOR; } diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index dc5002692..a1435639e 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -671,8 +671,9 @@ class CppGenerator : public BaseGenerator { } bool VectorElementUserFacing(const Type &type) const { - return opts_.g_cpp_std >= cpp::CPP_STD_17 && opts_.g_only_fixed_enums && - IsEnum(type); + return (opts_.scoped_enums && IsEnum(type)) || + (opts_.g_cpp_std >= cpp::CPP_STD_17 && opts_.g_only_fixed_enums && + IsEnum(type)); } void GenComment(const std::vector &dc, const char *prefix = "") {