Fix comparison of class objects (#4346)

This commit is contained in:
Ryszard Rozak 2023-07-07 13:20:23 +02:00 committed by GitHub
parent 9aa90569bf
commit da043ca16d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -1508,8 +1508,14 @@ public:
// For 'if (ptr)...' // For 'if (ptr)...'
operator bool() const { return m_objp; } operator bool() const { return m_objp; }
// In SV A == B iff both are handles to the same object (IEEE 1800-2017 8.4) // In SV A == B iff both are handles to the same object (IEEE 1800-2017 8.4)
bool operator==(const VlClassRef& rhs) const { return m_objp == rhs.m_objp; }; template <typename T_OtherClass>
bool operator!=(const VlClassRef& rhs) const { return m_objp != rhs.m_objp; }; bool operator==(const VlClassRef<T_OtherClass>& rhs) const {
return m_objp == rhs.m_objp;
};
template <typename T_OtherClass>
bool operator!=(const VlClassRef<T_OtherClass>& rhs) const {
return m_objp != rhs.m_objp;
};
}; };
template <typename T, typename U> template <typename T, typename U>

View File

@ -14,13 +14,22 @@ class Cls;
int i; int i;
endclass endclass
class ExtendCls extends Cls;
endclass
module t; module t;
initial begin initial begin
Cls a = new; Cls a = new;
Cls b = new; Cls b = new;
ExtendCls ext = new;
`check_ne(a, b) `check_ne(a, b)
`check_ne(a, ext)
`check_ne(ext, a)
a = b; a = b;
`check_eq(a, b) `check_eq(a, b)
a = ext;
`check_eq(a, ext)
`check_eq(ext, a)
$write("*-* All Finished *-*\n"); $write("*-* All Finished *-*\n");
$finish; $finish;
end end