From a415f044310851846f921a198738331c90addbc1 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 29 Sep 2020 10:21:08 +0200 Subject: [PATCH] COMP: cannot compare 'this' for different DynamicList types - Eg, cannot compare addresses of DynamicList and DynamicList [clang], so compare their cdata pointers instead. --- .../Lists/DynamicList/DynamicListI.H | 24 +++++++++++-------- .../PtrLists/PtrDynList/PtrDynListI.H | 6 +++-- .../Fields/DynamicField/DynamicFieldI.H | 16 +++++++++---- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H index 6b71e10211..c3518d70d9 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::swap DynamicList& 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::transfer DynamicList& 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::operator= template -template +template inline void Foam::DynamicList::operator= ( - const DynamicList& lst + const DynamicList& 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::operator= template -template +template inline void Foam::DynamicList::operator= ( - DynamicList&& lst + DynamicList&& 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 ab8dc7a2f8..c5de353b08 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::operator= const PtrDynList& 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::operator= PtrDynList&& 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 114480ba1b..bcf4470e9f 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::swap DynamicField& 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& cur = *this; + DynamicField& cur = *this; // Make addressable size identical to the allocated capacity const label oldSize1 = cur.expandStorage(); @@ -439,6 +440,12 @@ inline void Foam::DynamicField::transfer DynamicList& 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::transfer DynamicField& 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)