mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 12:05:50 +00:00
[C++] Add Command-Line Flag to Suppress MIN and MAX Enums (#7705)
Add the --no-minmax-values flag to prevent flatc from generating C++ enums with MIN and MAX enumerated values that otherwise would be set to the inclusive lower and upper bound respectively of the enum. This command-line flag is needed to avoid collisions when an enum that is being ported to FlatBuffers already has a MIN or MAX enumerated value. It is also needed to work around a long-standing problem with magic_enum that causes magic_enum to not see enumerated values that are not unique. For example, if FlatBuffers sets MIN = FOO and MAX = BAR, MIN and FOO share the same underlying value so they are not unique. The same is true of MAX and BAR. This prevents magic_enum from converting FOO and BAR to and from strings as well as causing magic_enum to return a count of enumerated values that is two fewer than it should be. Co-authored-by: Paul Serice <paul@serice.net>
This commit is contained in:
@@ -88,6 +88,9 @@ const static FlatCOption options[] = {
|
||||
{ "", "scoped-enums", "",
|
||||
"Use C++11 style scoped and strongly typed enums. Also implies "
|
||||
"--no-prefix." },
|
||||
{ "", "no-emit-min-max-enum-values", "",
|
||||
"Disable generation of MIN and MAX enumerated values for scoped enums "
|
||||
"and prefixed enums." },
|
||||
{ "", "swift-implementation-only", "",
|
||||
"Adds a @_implementationOnly to swift imports" },
|
||||
{ "", "gen-includes", "",
|
||||
@@ -464,6 +467,8 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
} else if (arg == "--scoped-enums") {
|
||||
opts.prefixed_enums = false;
|
||||
opts.scoped_enums = true;
|
||||
} else if (arg == "--no-emit-min-max-enum-values") {
|
||||
opts.emit_min_max_enum_values = false;
|
||||
} else if (arg == "--no-union-value-namespacing") {
|
||||
opts.union_value_namespacing = false;
|
||||
} else if (arg == "--gen-mutable") {
|
||||
|
||||
Reference in New Issue
Block a user