diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H index 6b71e10211cef4a65fccdedd93e6557e296020e2..c3518d70d9b783a2f8a9b412adf8128dc6d1eef1 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H @@ -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); } diff --git a/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynListI.H b/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynListI.H index ab8dc7a2f83b77ae646a3539665905b8bf73b508..c5de353b08bc4dba082d9735870cc2300fffc2df 100644 --- a/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynListI.H +++ b/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynListI.H @@ -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 } diff --git a/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H b/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H index 114480ba1b9a131502113b3ea6acf6f6d1d4b1f5..bcf4470e9ff03ea6366e768b37a9c84a9c2ef164 100644 --- a/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H +++ b/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H @@ -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)