Parameterized dynamic template error
Summary
Unpredictable behavior using nested dynamic parameterized templates.
See logs below
Steps and/or TTCN-3 code to reproduce
type union V {
V v,
integer n
};
template V m_d (
charstring p_name,
template V p_v
) := @dynamic {
log("NAM: ", p_name);
log("TPL: ", p_v);
log("VAL: ", value);
return match(value, p_v);
};
testcase TC1 () runs on C1 {
log("TC1 started");
var V f := {
v := {
n := 1
}
};
var template V m2 := m_d("2", V:{n:=1});
var template V m1 := m_d("1", V:{v:=m2});
log(match(f, m1));
}
What is the current bug behavior?
The following log message is produced on TS run:
Component type V1.C1 was initialized.
NAM: "1"
pure virtual method called
terminate called without an active exception
./v1_ts: Abort was called
./v1_ts(+0x15c2bf)[0x561191f742bf]
p__v.log() can not be called.
The bug is reproducible using nested templates for union type.
Record based types works well.
It also works well if templates are put directly in the match call:
match( m_d("1", V:{ v:=m_d("2", V:{n:=1} ) } ) )
What is the expected correct behavior?
This is a log after resolution.
Component type V1.C1 was initialized.
NAM: "1"
TPL: { v := @dynamic template }
VAL: { v := { n := 1 } }
NAM: "2"
TPL: { n := 1 }
VAL: { n := 1 }
matched
Terminating component type V1.C1.
Possible fixes
The abnormal behavior is happened because generated Dyn_Match_xxx class contains const reference to a temporary instance. Using copy constructor instead of reference will resolve the issue.
This is a working solution:
diff --git a/compiler2/ttcn3/TtcnTemplate.cc b/compiler2/ttcn3/TtcnTemplate.cc
index 505d64641..234a83124 100644
--- a/compiler2/ttcn3/TtcnTemplate.cc
+++ b/compiler2/ttcn3/TtcnTemplate.cc
@@ -5975,7 +5975,8 @@ compile_time:
ctor_init_list = mputstr(ctor_init_list, ", ");
ctor_call_str = mputstr(ctor_call_str, ", ");
}
- members_str = fp->generate_code_fpar(members_str);
+ members_str = fp->generate_code_object(members_str, "");
members_str = mputstr(members_str, ";\n");
ctor_sig_str = fp->generate_code_fpar(ctor_sig_str);
ctor_init_list = mputprintf(ctor_init_list, "%s(%s)",
It also would be nice to permit dynamic templates in SubType::chk_this_template(Template *templ):
diff --git a/compiler2/subtype.cc b/compiler2/subtype.cc
index 1ae4e6b6a..b44dc0353 100644
--- a/compiler2/subtype.cc
+++ b/compiler2/subtype.cc
@@ -2119,8 +2119,10 @@ void SubType::chk_this_template(Template *templ)
break;
case Template::TEMPLATE_ERROR:
break;
+ case Template::DYNAMIC_MATCH:
+ break;
default:
FATAL_ERROR("SubType::chk_this_template()");
break;
}
}
Titan version
10.0
Platform details (OS type and version)
Any version.
/cc @aknappqwt @mmagyari