diff --git a/TAO/TAO_IDL/ast/ast_union_branch.cpp b/TAO/TAO_IDL/ast/ast_union_branch.cpp index 8952cdfab21ea..b7da6dff6c3f1 100644 --- a/TAO/TAO_IDL/ast/ast_union_branch.cpp +++ b/TAO/TAO_IDL/ast/ast_union_branch.cpp @@ -181,22 +181,16 @@ AST_UnionBranch::label_list_length (void) void AST_UnionBranch::add_labels (AST_Union *u) { + const bool enum_labels = (u->udisc_type () == AST_Expression::EV_enum); for (UTL_LabellistActiveIterator i (this->pd_ll); !i.is_done (); i.next ()) { if (AST_UnionLabel::UL_default == i.item ()->label_kind ()) { - return; + continue; } - } - - const bool enum_labels = (u->udisc_type () == AST_Expression::EV_enum); - for (UTL_LabellistActiveIterator i (this->pd_ll); - !i.is_done (); - i.next ()) - { AST_Expression *ex = i.item ()->label_val (); UTL_ScopedName *n = ex->n (); diff --git a/TAO/tests/IDLv4/annotations/annotation_tests.cpp b/TAO/tests/IDLv4/annotations/annotation_tests.cpp index 73b2359c17848..35bcc728a83a4 100644 --- a/TAO/tests/IDLv4/annotations/annotation_tests.cpp +++ b/TAO/tests/IDLv4/annotations/annotation_tests.cpp @@ -4,7 +4,9 @@ #include #include #include - +#include +#include +#include #include namespace { @@ -1060,6 +1062,38 @@ annotation_tests () } } catch (Failed const &) {} + /* ------------------------------------------------------------------------- + * Empty union cases aliasing the default case must always be evaluated + * ------------------------------------------------------------------------- + * When the union has an enum discriminator, and one or more empty cases + * acting as an alias to the default case the IDL compiler was failing to + * resolve the ordinal value for these empty labels and this causes trouble + * for at least OpenDDS. + * + * This test is designed to verify that the condition is corrected by + * parsing a specially crafted union and validating the value of the + * label aliasing the default case. + */ + try { + Annotation_Test t ("empty union branch label"); + AST_Union *test_union = t.run ( + "enum disc {A, B, C};\n" + "union empty_union switch (disc) {\n" + "case A: long along;\n" + "case B: short bshort;\n" + "case C:\n" + "default: float cfloat;\n" + "};\n").assert_node("::empty_union"); + AST_Field **af = 0; + test_union->field(af, 2); + AST_UnionBranch *ub = dynamic_cast(*af); + AST_UnionLabel *ul = ub->label (); + if (ul->label_val()->ev()->u.ulval != 2) + { + t.failed("did not get the correct label value"); + } + } catch (Failed const &) {} + // Done, Print Overall Results Annotation_Test::results (); }