COMP: cannot compare 'this' for different DynamicList types

- Eg, cannot compare addresses of DynamicList<T,16> and DynamicList<T,8>
  [clang], so compare their cdata pointers instead.
This commit is contained in:
Mark Olesen
2020-09-29 10:21:08 +02:00
parent 9785029979
commit a415f04431
3 changed files with 30 additions and 16 deletions

View File

@ -397,7 +397,8 @@ inline void Foam::DynamicList<T, SizeMin>::swap
DynamicList<T, AnySizeMin>& lst
)
{
if (this == &lst)
// Cannot compare 'this' for different types, so use cdata()
if (this->cdata() == lst.cdata())
{
return; // Self-swap is a no-op
}
@ -439,7 +440,8 @@ Foam::DynamicList<T, SizeMin>::transfer
DynamicList<T, AnySizeMin>& lst
)
{
if (this == &lst)
// Cannot compare 'this' for different types, so use cdata()
if (this->cdata() == lst.cdata())
{
return; // Self-assignment is a no-op
}
@ -811,18 +813,19 @@ inline void Foam::DynamicList<T, SizeMin>::operator=
template<class T, int SizeMin>
template<int SizeMin2>
template<int AnySizeMin>
inline void Foam::DynamicList<T, SizeMin>::operator=
(
const DynamicList<T, SizeMin2>& lst
const DynamicList<T, AnySizeMin>& list
)
{
if (this == &lst)
// Cannot compare 'this' for different types, so use cdata()
if (this->cdata() == list.cdata())
{
return; // Self-assignment is a no-op
}
assignDynList(lst);
assignDynList(list);
}
@ -875,19 +878,20 @@ inline void Foam::DynamicList<T, SizeMin>::operator=
template<class T, int SizeMin>
template<int SizeMin2>
template<int AnySizeMin>
inline void Foam::DynamicList<T, SizeMin>::operator=
(
DynamicList<T, SizeMin2>&& lst
DynamicList<T, AnySizeMin>&& list
)
{
if (this == &lst)
// Cannot compare 'this' for different types, so use cdata()
if (this->cdata() == list.cdata())
{
return; // Self-assignment is a no-op
}
clear();
transfer(lst);
transfer(list);
}

View File

@ -471,7 +471,8 @@ inline void Foam::PtrDynList<T, SizeMin>::operator=
const PtrDynList<T, AnySizeMin>& list
)
{
if (this == &list)
// Cannot compare 'this' for different types, so use cdata()
if (this->cdata() == list.cdata())
{
return; // Self-assignment is a no-op
}
@ -522,7 +523,8 @@ inline void Foam::PtrDynList<T, SizeMin>::operator=
PtrDynList<T, AnySizeMin>&& list
)
{
if (this == &list)
// Cannot compare 'this' for different types, so use cdata()
if (this->cdata() == list.cdata())
{
return; // Self-assignment is a no-op
}

View File

@ -399,12 +399,13 @@ inline void Foam::DynamicField<T, SizeMin>::swap
DynamicField<T, AnySizeMin>& lst
)
{
if (this == &lst)
// Cannot compare 'this' for different types, so use cdata()
if (this->cdata() == lst.cdata())
{
return; // Self-swap is a no-op
}
DynamicList<T, SizeMin>& cur = *this;
DynamicField<T, SizeMin>& cur = *this;
// Make addressable size identical to the allocated capacity
const label oldSize1 = cur.expandStorage();
@ -439,6 +440,12 @@ inline void Foam::DynamicField<T, SizeMin>::transfer
DynamicList<T, AnySizeMin>& list
)
{
// Cannot compare 'this' for different types, so use cdata()
if (this->cdata() == list.cdata())
{
return; // Self-swap is a no-op
}
// Take over storage as-is (without shrink, without using SizeMin)
// clear addressing and storage for old list.
capacity_ = list.capacity();
@ -455,9 +462,10 @@ inline void Foam::DynamicField<T, SizeMin>::transfer
DynamicField<T, AnySizeMin>& list
)
{
if (this == &list)
// Cannot compare 'this' for different types, so use cdata()
if (this->cdata() == list.cdata())
{
return; // Self-assignment is a no-op
return; // Self-swap is a no-op
}
// Take over storage as-is (without shrink, without using SizeMin)