Skip to content

Commit

Permalink
Merge pull request DOCGroup#1551 from DOCGroup/plm_jira_333
Browse files Browse the repository at this point in the history
Fix for issue DOCGroup#1550 - empty case evaluation on unions with enum discriminators
  • Loading branch information
pmesnier authored Jun 16, 2021
2 parents 84438e5 + 9b6353b commit eff3988
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
10 changes: 2 additions & 8 deletions TAO/TAO_IDL/ast/ast_union_branch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();

Expand Down
36 changes: 35 additions & 1 deletion TAO/tests/IDLv4/annotations/annotation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#include <ast_porttype.h>
#include <ast_eventtype.h>
#include <ast_component.h>

#include <ast_union_branch.h>
#include <ast_union_label.h>
#include <ast_expression.h>
#include <string>

namespace {
Expand Down Expand Up @@ -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<AST_Union>("::empty_union");
AST_Field **af = 0;
test_union->field(af, 2);
AST_UnionBranch *ub = dynamic_cast<AST_UnionBranch *>(*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 ();
}

0 comments on commit eff3988

Please sign in to comment.