From 3e52fecd1ed1c68e62b441c9e227b64351eef1c4 Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Wed, 1 Jun 2016 10:23:44 +0300 Subject: [PATCH] Don't generate MIN & MAX enum values if "--no-prefix" is used. Close #3892 --- src/idl_gen_cpp.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index a163ee816..1cb801356 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -179,17 +179,19 @@ static void GenEnum(const Parser &parser, EnumDef &enum_def, maxv = !maxv || maxv->value < ev.value ? &ev : maxv; anyv |= ev.value; } - assert(minv && maxv); - if (enum_def.attributes.Lookup("bit_flags")) { - if (minv->value != 0) // If the user didn't defined NONE value - code += " " + GenEnumVal(enum_def, "NONE", parser.opts) + " = 0,\n"; - if (maxv->value != anyv) // If the user didn't defined ANY value - code += " " + GenEnumVal(enum_def, "ANY", parser.opts) + " = " + NumToString(anyv) + "\n"; - } else { // MIN & MAX are useless for bit_flags - code += " " + GenEnumVal(enum_def, "MIN", parser.opts) + " = "; - code += GenEnumVal(enum_def, minv->name, parser.opts) + ",\n"; - code += " " + GenEnumVal(enum_def, "MAX", parser.opts) + " = "; - code += GenEnumVal(enum_def, maxv->name, parser.opts) + "\n"; + if (parser.opts.scoped_enums || parser.opts.prefixed_enums) { + assert(minv && maxv); + if (enum_def.attributes.Lookup("bit_flags")) { + if (minv->value != 0) // If the user didn't defined NONE value + code += " " + GenEnumVal(enum_def, "NONE", parser.opts) + " = 0,\n"; + if (maxv->value != anyv) // If the user didn't defined ANY value + code += " " + GenEnumVal(enum_def, "ANY", parser.opts) + " = " + NumToString(anyv) + "\n"; + } else { // MIN & MAX are useless for bit_flags + code += " " + GenEnumVal(enum_def, "MIN", parser.opts) + " = "; + code += GenEnumVal(enum_def, minv->name, parser.opts) + ",\n"; + code += " " + GenEnumVal(enum_def, "MAX", parser.opts) + " = "; + code += GenEnumVal(enum_def, maxv->name, parser.opts) + "\n"; + } } code += "};\n"; if (parser.opts.scoped_enums && enum_def.attributes.Lookup("bit_flags"))