Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Eclipse Projects
Eclipse Titan
titan.core
Commits
aed5a062
Commit
aed5a062
authored
May 27, 2020
by
Jeno Attila Balasko
Committed by
Gerrit Code Review
May 27, 2020
Browse files
Merge "OOP: fixed assignment of subclass object to a superclass reference (bug 552011)"
parents
611b4d21
7dd8e4a6
Changes
2
Hide whitespace changes
Inline
Side-by-side
core/OOP.hh
View file @
aed5a062
...
...
@@ -79,6 +79,19 @@ public:
}
}
template
<
typename
T2
>
OBJECT_REF
(
OBJECT_REF
<
T2
>&
p_other
)
{
if
(
p_other
!=
NULL_VALUE
)
{
ptr
=
dynamic_cast
<
T
*>
(
*
p_other
);
if
(
ptr
!=
NULL
)
{
ptr
->
add_ref
();
}
else
{
TTCN_error
(
"Invalid dynamic type of initial value."
);
}
}
}
void
clean_up
()
{
if
(
ptr
!=
NULL
)
{
if
(
ptr
->
remove_ref
())
{
...
...
@@ -106,6 +119,21 @@ public:
return
*
this
;
}
template
<
typename
T2
>
OBJECT_REF
&
operator
=
(
OBJECT_REF
<
T2
>&
p_other
)
{
clean_up
();
if
(
p_other
!=
NULL_VALUE
)
{
ptr
=
dynamic_cast
<
T
*>
(
*
p_other
);
if
(
ptr
!=
NULL
)
{
ptr
->
add_ref
();
}
else
{
TTCN_error
(
"Invalid dynamic type of assigned value."
);
}
}
return
*
this
;
}
boolean
operator
==
(
null_type
)
const
{
// equality operator (with null reference)
return
ptr
==
NULL
;
}
...
...
regression_test/oop/oop.ttcn
View file @
aed5a062
...
...
@@ -269,6 +269,15 @@ testcase tc_equality() runs on CT {
if
(
v_ref2
!=
v_base
)
{
setverdict
(
fail
,
"Inequality of object and indirect reference to object failed"
);
}
var
SubClass
v_sub
:=
SubClass
.
create
(
4
,
{
1
,
2
,
4
},
"a"
,
'
FF
'
O
,
(
0.0
..
10.0
));
var
BaseClass
v_ref3
:=
v_sub
;
if
(
not
v_ref3
==
v_sub
)
{
setverdict
(
fail
,
"Equality of subclass object and superclass reference failed"
);
}
if
(
v_ref3
!=
v_sub
)
{
setverdict
(
fail
,
"Inquality of subclass object and superclass reference failed"
);
}
setverdict
(
pass
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment