update C++ generator to emit scoped enums in vector of unions (#7075)
authorDerek Bailey <derekbailey@google.com>
Thu, 3 Feb 2022 06:29:21 +0000 (22:29 -0800)
committerGitHub <noreply@github.com>
Thu, 3 Feb 2022 06:29:21 +0000 (22:29 -0800)
include/flatbuffers/idl.h
src/idl_gen_cpp.cpp

index 039e3c5..0b11ba4 100644 (file)
@@ -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;
 }
index dc50026..a143563 100644 (file)
@@ -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<std::string> &dc, const char *prefix = "") {