From b0c88dff584b9029de36c56a74ac7fc1d6bde762 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Tue, 5 Nov 2019 11:10:49 +0100 Subject: [PATCH] ENH: treat self-assignment as no-op instead of a Fatal (#1473) - this can help if using std algorithms that return a const reference such as std::min() does. --- etc/codeTemplates/source/_Template.C | 9 ++---- .../template/_TemplateTemplate.C | 5 +-- src/OSspecific/POSIX/regExp/regExpPosixI.H | 6 +++- .../containers/Bits/PackedList/PackedListI.H | 12 ++++++- src/OpenFOAM/containers/Bits/bitSet/bitSetI.H | 1 + .../Circulators/Circulator/CirculatorI.H | 6 ++-- .../ConstCirculator/ConstCirculatorI.H | 6 ++-- .../DictionaryBase/DictionaryBase.C | 9 ++++-- .../HashTables/HashPtrTable/HashPtrTable.C | 8 ++--- .../HashTables/HashTable/HashTable.C | 20 +++++++----- .../linkTypes/DLListBase/DLListBaseI.H | 10 ++++++ .../linkTypes/SLListBase/SLListBaseI.H | 10 ++++++ .../Lists/CompactListList/CompactListList.C | 11 +++++++ .../Lists/CompactListList/CompactListListI.H | 10 ++++++ .../Lists/Distribution/Distribution.C | 6 ++-- .../Lists/DynamicList/DynamicListI.H | 32 ++++++++++++++++--- .../containers/Lists/FixedList/FixedListI.H | 20 ++++++++++++ src/OpenFOAM/containers/Lists/List/List.C | 18 +++++++---- src/OpenFOAM/containers/Lists/List/ListI.H | 2 +- .../Lists/SortableList/SortableList.C | 15 +++++++++ src/OpenFOAM/containers/Lists/UList/UListI.H | 5 +++ .../PtrLists/PtrDynList/PtrDynListI.H | 30 +++++++++++++++++ .../containers/PtrLists/PtrList/PtrList.C | 6 ++-- .../containers/PtrLists/UPtrList/UPtrListI.H | 4 +-- .../IOobjects/CompactIOField/CompactIOField.C | 5 +++ .../IOobjects/CompactIOList/CompactIOList.C | 2 +- src/OpenFOAM/db/IOstreams/token/tokenI.H | 15 +++++++++ src/OpenFOAM/db/dictionary/dictionary.C | 13 +++----- src/OpenFOAM/db/dictionary/entry/entry.C | 25 ++++++++------- .../db/objectRegistry/objectRegistry.C | 4 +-- .../DimensionedField/DimensionedField.C | 12 ++----- .../FieldFields/FieldField/FieldField.C | 15 +++------ .../Fields/DynamicField/DynamicFieldI.H | 15 +++++++-- src/OpenFOAM/fields/Fields/Field/Field.C | 8 ++--- .../GeometricField/GeometricField.C | 8 ++--- .../LduMatrix/LduMatrix/LduMatrixOperations.C | 5 ++- src/OpenFOAM/matrices/Matrix/Matrix.C | 23 +++++++------ .../lduMatrix/lduMatrix/lduMatrixOperations.C | 6 ++-- .../matrices/simpleMatrix/simpleMatrix.C | 5 ++- src/OpenFOAM/memory/autoPtr/autoPtrI.H | 3 ++ src/OpenFOAM/memory/tmp/tmpI.H | 10 ++++++ src/OpenFOAM/memory/tmp/tmpNrcI.H | 10 ++++++ .../mapPolyMesh/mapDistribute/mapDistribute.C | 13 +++++--- .../mapDistribute/mapDistributeBase.C | 14 +++++--- .../primitives/strings/keyType/keyTypeI.H | 9 ++---- .../strings/lists/hashedWordListI.H | 5 +++ .../primitives/strings/regex/regExpCxxI.H | 8 +++-- .../primitives/strings/string/stringI.H | 2 +- .../primitives/strings/wordRe/wordReI.H | 9 ++---- .../hexRef8/refinementHistory.C | 5 +-- src/finiteArea/faMatrices/faMatrix/faMatrix.C | 5 ++- .../convectionScheme/convectionScheme.C | 4 +-- .../fvMatrices/fvMatrix/fvMatrix.C | 6 ++-- .../fieldAverageItem/fieldAverageItem.C | 5 +-- .../CollisionRecordList/CollisionRecordList.C | 6 ++-- .../PairCollisionRecord/PairCollisionRecord.C | 6 ++-- .../WallCollisionRecord/WallCollisionRecord.C | 6 ++-- .../bufferedAccumulator/bufferedAccumulator.C | 8 ++--- .../distribution/distribution.C | 5 +-- .../surfaceFeatures/surfaceFeatures.C | 5 +-- src/sampling/surface/cutting/cuttingPlane.C | 6 ++-- .../surface/cutting/cuttingSurfaceBase.C | 4 +-- src/surfMesh/MeshedSurface/MeshedSurface.C | 10 ++++++ .../UnsortedMeshedSurface.C | 10 ++++++ src/surfMesh/triSurface/triSurface.C | 5 +++ 65 files changed, 391 insertions(+), 210 deletions(-) diff --git a/etc/codeTemplates/source/_Template.C b/etc/codeTemplates/source/_Template.C index c8f231a79e3..8708db05038 100644 --- a/etc/codeTemplates/source/_Template.C +++ b/etc/codeTemplates/source/_Template.C @@ -89,19 +89,16 @@ Foam::CLASSNAME::~CLASSNAME() void Foam::CLASSNAME::operator=(const CLASSNAME& rhs) { - // Check for assignment to self if (this == &rhs) { - FatalErrorInFunction - << "Attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } } -// * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * * // -// * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // // ************************************************************************* // diff --git a/etc/codeTemplates/template/_TemplateTemplate.C b/etc/codeTemplates/template/_TemplateTemplate.C index 9c5c3caa971..8adec14c390 100644 --- a/etc/codeTemplates/template/_TemplateTemplate.C +++ b/etc/codeTemplates/template/_TemplateTemplate.C @@ -102,12 +102,9 @@ void Foam::CLASSNAME<TemplateArgument>::operator= const CLASSNAME<TemplateArgument>& rhs ) { - // Check for assignment to self if (this == &rhs) { - FatalErrorInFunction - << "Attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } } diff --git a/src/OSspecific/POSIX/regExp/regExpPosixI.H b/src/OSspecific/POSIX/regExp/regExpPosixI.H index 60cf6d9e5c9..3d8df849af2 100644 --- a/src/OSspecific/POSIX/regExp/regExpPosixI.H +++ b/src/OSspecific/POSIX/regExp/regExpPosixI.H @@ -126,7 +126,11 @@ inline bool Foam::regExpPosix::search(const std::string& text) const inline void Foam::regExpPosix::swap(regExpPosix& rgx) { - std::swap(preg_, rgx.preg_); + if (this != &rgx) + { + // Self-swap is a no-op + std::swap(preg_, rgx.preg_); + } } diff --git a/src/OpenFOAM/containers/Bits/PackedList/PackedListI.H b/src/OpenFOAM/containers/Bits/PackedList/PackedListI.H index 4919d62568c..4fe51d14e86 100644 --- a/src/OpenFOAM/containers/Bits/PackedList/PackedListI.H +++ b/src/OpenFOAM/containers/Bits/PackedList/PackedListI.H @@ -320,6 +320,7 @@ inline void Foam::PackedList<Width>::reference::operator= const reference& other ) { + // Accepts self-assignment this->set(other.get()); } @@ -556,6 +557,11 @@ inline std::streamsize Foam::PackedList<Width>::byteSize() const template<unsigned Width> inline void Foam::PackedList<Width>::swap(PackedList<Width>& rhs) { + if (this == &rhs) + { + return; // Self-swap is a no-op + } + blocks_.swap(rhs.blocks_); Foam::Swap(size_, rhs.size_); } @@ -564,8 +570,12 @@ inline void Foam::PackedList<Width>::swap(PackedList<Width>& rhs) template<unsigned Width> inline void Foam::PackedList<Width>::transfer(PackedList<Width>& rhs) { - blocks_.transfer(rhs.blocks_); + if (this == &rhs) + { + return; // Self-assignment is a no-op + } + blocks_.transfer(rhs.blocks_); size_ = rhs.size_; rhs.size_ = 0; } diff --git a/src/OpenFOAM/containers/Bits/bitSet/bitSetI.H b/src/OpenFOAM/containers/Bits/bitSet/bitSetI.H index 161f68c60b0..c3332a4a2f1 100644 --- a/src/OpenFOAM/containers/Bits/bitSet/bitSetI.H +++ b/src/OpenFOAM/containers/Bits/bitSet/bitSetI.H @@ -197,6 +197,7 @@ inline void Foam::bitSet::reference::operator= const reference& other ) { + // Accepts self-assignment set(other.get()); } diff --git a/src/OpenFOAM/containers/Circulators/Circulator/CirculatorI.H b/src/OpenFOAM/containers/Circulators/Circulator/CirculatorI.H index 9da7624c223..88aa28fe42a 100644 --- a/src/OpenFOAM/containers/Circulators/Circulator/CirculatorI.H +++ b/src/OpenFOAM/containers/Circulators/Circulator/CirculatorI.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2012-2015 OpenFOAM Foundation + Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -170,12 +171,9 @@ void Foam::Circulator<ContainerType>::operator= const Circulator<ContainerType>& rhs ) { - // Check for assignment to self if (this == &rhs) { - FatalErrorInFunction - << "Attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } begin_ = rhs.begin_; diff --git a/src/OpenFOAM/containers/Circulators/ConstCirculator/ConstCirculatorI.H b/src/OpenFOAM/containers/Circulators/ConstCirculator/ConstCirculatorI.H index 7c8ed24f3f3..fded93cc55e 100644 --- a/src/OpenFOAM/containers/Circulators/ConstCirculator/ConstCirculatorI.H +++ b/src/OpenFOAM/containers/Circulators/ConstCirculator/ConstCirculatorI.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2012-2015 OpenFOAM Foundation + Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -175,12 +176,9 @@ void Foam::ConstCirculator<ContainerType>::operator= const ConstCirculator<ContainerType>& rhs ) { - // Check for assignment to self if (this == &rhs) { - FatalErrorInFunction - << "Attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } begin_ = rhs.begin_; diff --git a/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.C b/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.C index a2f73e18281..e2df5eb424e 100644 --- a/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.C +++ b/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.C @@ -232,6 +232,11 @@ void Foam::DictionaryBase<IDLListType, T>::transfer DictionaryBase<IDLListType, T>& dict ) { + if (this == &dict) + { + return; // Self-assignment is a no-op + } + IDLListType::transfer(dict); hashedTs_.transfer(dict.hashedTs_); } @@ -247,9 +252,7 @@ void Foam::DictionaryBase<IDLListType, T>::operator= { if (this == &dict) { - FatalErrorInFunction - << "attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } IDLListType::operator=(dict); diff --git a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.C b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.C index 8f93c5f3d7d..c8a8fffed5e 100644 --- a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.C +++ b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.C @@ -149,9 +149,7 @@ void Foam::HashPtrTable<T, Key, Hash>::operator= { if (this == &rhs) { - FatalErrorInFunction - << "attempted copy assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } this->clear(); @@ -179,9 +177,7 @@ void Foam::HashPtrTable<T, Key, Hash>::operator= { if (this == &rhs) { - FatalErrorInFunction - << "attempted move assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } this->clear(); diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C index d2b0c45f6f3..17d0121bfc3 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C @@ -656,6 +656,11 @@ void Foam::HashTable<T, Key, Hash>::clearStorage() template<class T, class Key, class Hash> void Foam::HashTable<T, Key, Hash>::swap(HashTable<T, Key, Hash>& rhs) { + if (this == &rhs) + { + return; // Self-swap is a no-op + } + Foam::Swap(size_, rhs.size_); Foam::Swap(capacity_, rhs.capacity_); Foam::Swap(table_, rhs.table_); @@ -665,6 +670,11 @@ void Foam::HashTable<T, Key, Hash>::swap(HashTable<T, Key, Hash>& rhs) template<class T, class Key, class Hash> void Foam::HashTable<T, Key, Hash>::transfer(HashTable<T, Key, Hash>& rhs) { + if (this == &rhs) + { + return; // Self-assignment is a no-op + } + clear(); swap(rhs); } @@ -759,12 +769,9 @@ void Foam::HashTable<T, Key, Hash>::operator= const HashTable<T, Key, Hash>& rhs ) { - // Check for assignment to self if (this == &rhs) { - FatalErrorInFunction - << "attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } if (!capacity_) @@ -813,12 +820,9 @@ void Foam::HashTable<T, Key, Hash>::operator= HashTable<T, Key, Hash>&& rhs ) { - // Check for assignment to self if (this == &rhs) { - FatalErrorInFunction - << "attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } transfer(rhs); diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H index 13d1d7b4d79..02cafc82b05 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H @@ -185,6 +185,11 @@ inline void Foam::DLListBase::clear() inline void Foam::DLListBase::swap(DLListBase& lst) { + if (this == &lst) + { + return; // Self-swap is a no-op + } + std::swap(first_, lst.first_); std::swap(last_, lst.last_); std::swap(size_, lst.size_); @@ -193,6 +198,11 @@ inline void Foam::DLListBase::swap(DLListBase& lst) inline void Foam::DLListBase::transfer(DLListBase& lst) { + if (this == &lst) + { + return; // Self-assignment is a no-op + } + first_ = lst.first_; last_ = lst.last_; size_ = lst.size_; diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H index 42c08708c6c..d9a44565217 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H @@ -143,6 +143,11 @@ inline void Foam::SLListBase::clear() inline void Foam::SLListBase::swap(SLListBase& lst) { + if (this == &lst) + { + return; // Self-swap is a no-op + } + std::swap(last_, lst.last_); std::swap(size_, lst.size_); } @@ -150,6 +155,11 @@ inline void Foam::SLListBase::swap(SLListBase& lst) inline void Foam::SLListBase::transfer(SLListBase& lst) { + if (this == &lst) + { + return; // Self-assignment is a no-op + } + last_ = lst.last_; size_ = lst.size_; diff --git a/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.C b/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.C index d837f41b9fc..f2fbd29724d 100644 --- a/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.C +++ b/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -203,6 +204,11 @@ void Foam::CompactListList<T, Container>::swap CompactListList<T, Container>& lst ) { + if (this == &lst) + { + return; // Self-swap is a no-op + } + Foam::Swap(size_, lst.size_); offsets_.swap(lst.offsets_); m_.swap(lst.m_); @@ -215,6 +221,11 @@ void Foam::CompactListList<T, Container>::transfer CompactListList<T, Container>& lst ) { + if (this == &lst) + { + return; // Self-assignment is a no-op + } + size_ = lst.size_; offsets_.transfer(lst.offsets_); m_.transfer(lst.m_); diff --git a/src/OpenFOAM/containers/Lists/CompactListList/CompactListListI.H b/src/OpenFOAM/containers/Lists/CompactListList/CompactListListI.H index ff79c865be3..1a3c2613abc 100644 --- a/src/OpenFOAM/containers/Lists/CompactListList/CompactListListI.H +++ b/src/OpenFOAM/containers/Lists/CompactListList/CompactListListI.H @@ -303,6 +303,11 @@ inline void Foam::CompactListList<T, Container>::operator= const CompactListList<T, Container>& lst ) { + if (this == &lst) + { + return; // Self-assignment is a no-op + } + size_ = lst.size_; offsets_ = lst.offsets_, m_ = lst.m_; @@ -315,6 +320,11 @@ inline void Foam::CompactListList<T, Container>::operator= CompactListList<T, Container>&& lst ) { + if (this == &lst) + { + return; // Self-assignment is a no-op + } + transfer(lst); } diff --git a/src/OpenFOAM/containers/Lists/Distribution/Distribution.C b/src/OpenFOAM/containers/Lists/Distribution/Distribution.C index 19b29270f91..1e5d2e541b6 100644 --- a/src/OpenFOAM/containers/Lists/Distribution/Distribution.C +++ b/src/OpenFOAM/containers/Lists/Distribution/Distribution.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -557,12 +558,9 @@ void Foam::Distribution<Type>::operator= const Distribution<Type>& rhs ) { - // Check for assignment to self if (this == &rhs) { - FatalErrorInFunction - << "Attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } List<List<scalar>>::operator=(rhs); diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H index d74bc281db1..6b71e10211c 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H @@ -397,6 +397,11 @@ inline void Foam::DynamicList<T, SizeMin>::swap DynamicList<T, AnySizeMin>& lst ) { + if (this == &lst) + { + return; // Self-swap is a no-op + } + DynamicList<T, SizeMin>& cur = *this; // Make addressable size identical to the allocated capacity @@ -434,6 +439,11 @@ Foam::DynamicList<T, SizeMin>::transfer DynamicList<T, AnySizeMin>& lst ) { + if (this == &lst) + { + return; // Self-assignment is a no-op + } + // Take over storage as-is (without shrink, without using SizeMin) // clear addressing and storage for old lst. capacity_ = lst.capacity(); @@ -793,8 +803,7 @@ inline void Foam::DynamicList<T, SizeMin>::operator= { if (this == &lst) { - FatalErrorInFunction - << "Attempted assignment to self" << abort(FatalError); + return; // Self-assignment is a no-op } assignDynList(lst); @@ -808,6 +817,11 @@ inline void Foam::DynamicList<T, SizeMin>::operator= const DynamicList<T, SizeMin2>& lst ) { + if (this == &lst) + { + return; // Self-assignment is a no-op + } + assignDynList(lst); } @@ -852,8 +866,7 @@ inline void Foam::DynamicList<T, SizeMin>::operator= { if (this == &lst) { - FatalErrorInFunction - << "Attempted assignment to self" << abort(FatalError); + return; // Self-assignment is a no-op } clear(); @@ -868,6 +881,11 @@ inline void Foam::DynamicList<T, SizeMin>::operator= DynamicList<T, SizeMin2>&& lst ) { + if (this == &lst) + { + return; // Self-assignment is a no-op + } + clear(); transfer(lst); } @@ -887,7 +905,11 @@ inline void Foam::DynamicList<T, SizeMin>::operator= // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // template<class T, int SizeMin1, int SizeMin2> -inline void Foam::Swap(DynamicList<T, SizeMin1>& a, DynamicList<T, SizeMin2>& b) +inline void Foam::Swap +( + DynamicList<T, SizeMin1>& a, + DynamicList<T, SizeMin2>& b +) { a.swap(b); } diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H index d6e5f62bc61..47057ec9957 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H @@ -331,6 +331,11 @@ inline void Foam::FixedList<T, N>::setSize(const label n) template<class T, unsigned N> inline void Foam::FixedList<T, N>::swap(FixedList<T, N>& list) { + if (this == &list) + { + return; // Self-swap is a no-op + } + for (unsigned i=0; i<N; ++i) { Foam::Swap(v_[i], list.v_[i]); @@ -341,6 +346,11 @@ inline void Foam::FixedList<T, N>::swap(FixedList<T, N>& list) template<class T, unsigned N> inline void Foam::FixedList<T, N>::transfer(FixedList<T, N>& list) { + if (this == &list) + { + return; // Self-assignment is a no-op + } + for (unsigned i=0; i<N; ++i) { v_[i] = std::move(list[i]); @@ -428,6 +438,11 @@ inline void Foam::FixedList<T, N>::operator=(const T& val) template<class T, unsigned N> inline void Foam::FixedList<T, N>::operator=(const FixedList<T, N>& list) { + if (this == &list) + { + return; // Self-assignment is a no-op + } + for (unsigned i=0; i<N; ++i) { v_[i] = list.v_[i]; @@ -437,6 +452,11 @@ inline void Foam::FixedList<T, N>::operator=(const FixedList<T, N>& list) template<class T, unsigned N> inline void Foam::FixedList<T, N>::operator=(FixedList<T, N>&& list) { + if (this == &list) + { + return; // Self-assignment is a no-op + } + // No significant speedup observed for copy assignment on simple types, // use move assignment for generality with more complex types for (unsigned i=0; i<N; ++i) diff --git a/src/OpenFOAM/containers/Lists/List/List.C b/src/OpenFOAM/containers/Lists/List/List.C index d91dcc87946..426efed774e 100644 --- a/src/OpenFOAM/containers/Lists/List/List.C +++ b/src/OpenFOAM/containers/Lists/List/List.C @@ -435,6 +435,11 @@ void Foam::List<T>::resize(const label newSize, const T& val) template<class T> void Foam::List<T>::transfer(List<T>& list) { + if (this == &list) + { + return; // Self-assignment is a no-op + } + // Clear and swap - could also check for self assignment clear(); this->size_ = list.size_; @@ -472,6 +477,11 @@ void Foam::List<T>::transfer(SortableList<T>& list) template<class T> void Foam::List<T>::operator=(const UList<T>& a) { + if (this == &a) + { + return; // Self-assignment is a no-op + } + reAlloc(a.size_); const label len = this->size_; @@ -505,9 +515,7 @@ void Foam::List<T>::operator=(const List<T>& list) { if (this == &list) { - FatalErrorInFunction - << "attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } operator=(static_cast<const UList<T>&>(list)); @@ -581,9 +589,7 @@ void Foam::List<T>::operator=(List<T>&& list) { if (this == &list) { - FatalErrorInFunction - << "attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } transfer(list); diff --git a/src/OpenFOAM/containers/Lists/List/ListI.H b/src/OpenFOAM/containers/Lists/List/ListI.H index b6e2d2f990a..c32eef53948 100644 --- a/src/OpenFOAM/containers/Lists/List/ListI.H +++ b/src/OpenFOAM/containers/Lists/List/ListI.H @@ -193,7 +193,7 @@ inline void Foam::List<T>::append(const UList<T>& list) if (this == &list) { FatalErrorInFunction - << "attempted appending to self" << abort(FatalError); + << "Attempted appending to self" << abort(FatalError); } label idx = this->size(); diff --git a/src/OpenFOAM/containers/Lists/SortableList/SortableList.C b/src/OpenFOAM/containers/Lists/SortableList/SortableList.C index 817e9c00d05..4d3d755a2fd 100644 --- a/src/OpenFOAM/containers/Lists/SortableList/SortableList.C +++ b/src/OpenFOAM/containers/Lists/SortableList/SortableList.C @@ -197,6 +197,11 @@ void Foam::SortableList<T>::partialReverseSort(label n, label start) template<class T> void Foam::SortableList<T>::swap(SortableList<T>& lst) { + if (this == &lst) + { + return; // Self-swap is a no-op + } + List<T>::swap(lst); indices_.swap(lst.indices_); } @@ -223,6 +228,11 @@ inline void Foam::SortableList<T>::operator=(const UList<T>& lst) template<class T> inline void Foam::SortableList<T>::operator=(const SortableList<T>& lst) { + if (this == &lst) + { + return; // Self-assigment is a no-op + } + List<T>::operator=(lst); indices_ = lst.indices(); } @@ -239,6 +249,11 @@ inline void Foam::SortableList<T>::operator=(List<T>&& lst) template<class T> inline void Foam::SortableList<T>::operator=(SortableList<T>&& lst) { + if (this == &lst) + { + return; // Self-assigment is a no-op + } + clear(); this->swap(lst); } diff --git a/src/OpenFOAM/containers/Lists/UList/UListI.H b/src/OpenFOAM/containers/Lists/UList/UListI.H index 8066626e650..4a8452487f7 100644 --- a/src/OpenFOAM/containers/Lists/UList/UListI.H +++ b/src/OpenFOAM/containers/Lists/UList/UListI.H @@ -380,6 +380,11 @@ inline bool Foam::UList<T>::empty() const noexcept template<class T> inline void Foam::UList<T>::swap(UList<T>& list) { + if (&list == this) + { + return; // Self-swap is a no-op + } + Foam::Swap(size_, list.size_); Foam::Swap(v_, list.v_); } diff --git a/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynListI.H b/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynListI.H index b3045ad2535..d6845719d8a 100644 --- a/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynListI.H +++ b/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynListI.H @@ -369,6 +369,11 @@ inline void Foam::PtrDynList<T, SizeMin>::operator= const PtrList<T>& list ) { + if (this == &list) + { + return; // Self-assignment is a no-op + } + PtrList<T>::operator=(list); capacity_ = PtrList<T>::size(); } @@ -380,6 +385,11 @@ inline void Foam::PtrDynList<T, SizeMin>::operator= const PtrDynList<T, SizeMin>& list ) { + if (this == &list) + { + return; // Self-assignment is a no-op + } + PtrList<T>::operator=(list); capacity_ = PtrList<T>::size(); } @@ -392,6 +402,11 @@ inline void Foam::PtrDynList<T, SizeMin>::operator= const PtrDynList<T, AnySizeMin>& list ) { + if (this == &list) + { + return; // Self-assignment is a no-op + } + PtrList<T>::operator=(list); capacity_ = PtrList<T>::size(); } @@ -403,6 +418,11 @@ inline void Foam::PtrDynList<T, SizeMin>::operator= PtrList<T>&& list ) { + if (this == &list) + { + return; // Self-assignment is a no-op + } + PtrList<T>::transfer(list); capacity_ = PtrList<T>::size(); list.clearStorage(); @@ -415,6 +435,11 @@ inline void Foam::PtrDynList<T, SizeMin>::operator= PtrDynList<T, SizeMin>&& list ) { + if (this == &list) + { + return; // Self-assignment is a no-op + } + PtrList<T>::transfer(list); capacity_ = list.capacity(); list.clearStorage(); @@ -428,6 +453,11 @@ inline void Foam::PtrDynList<T, SizeMin>::operator= PtrDynList<T, AnySizeMin>&& list ) { + if (this == &list) + { + return; // Self-assignment is a no-op + } + PtrList<T>::transfer(list); capacity_ = list.capacity(); list.clearStorage(); diff --git a/src/OpenFOAM/containers/PtrLists/PtrList/PtrList.C b/src/OpenFOAM/containers/PtrLists/PtrList/PtrList.C index b75abd5366a..7df86c8da32 100644 --- a/src/OpenFOAM/containers/PtrLists/PtrList/PtrList.C +++ b/src/OpenFOAM/containers/PtrLists/PtrList/PtrList.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -134,9 +134,7 @@ void Foam::PtrList<T>::operator=(const PtrList<T>& list) { if (this == &list) { - FatalErrorInFunction - << "attempted assignment to self for type " << typeid(T).name() - << abort(FatalError); + return; // Self-assignment is a no-op } const label oldLen = this->size(); diff --git a/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H b/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H index 2d56f368bb9..6c29a834a79 100644 --- a/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H +++ b/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H @@ -203,7 +203,7 @@ inline const T& Foam::UPtrList<T>::operator[](const label i) const { FatalErrorInFunction << "Cannot dereference nullptr at index " << i - << " in range [0," << size() << ")" + << " in range [0," << size() << ")\n" << abort(FatalError); } @@ -220,7 +220,7 @@ inline T& Foam::UPtrList<T>::operator[](const label i) { FatalErrorInFunction << "Cannot dereference nullptr at index " << i - << " in range [0," << size() << ")" + << " in range [0," << size() << ")\n" << abort(FatalError); } diff --git a/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.C b/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.C index 2763bcdfb13..c7ab9b7ac9a 100644 --- a/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.C +++ b/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.C @@ -215,6 +215,11 @@ void Foam::CompactIOField<T, BaseType>::operator= const CompactIOField<T, BaseType>& rhs ) { + if (this == &rhs) + { + return; // Self-assigment is a no-op + } + Field<T>::operator=(rhs); } diff --git a/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C b/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C index c13cf8ccd73..cfd3507fca2 100644 --- a/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C +++ b/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2015-2018 OpenCFD Ltd. + Copyright (C) 2015-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. diff --git a/src/OpenFOAM/db/IOstreams/token/tokenI.H b/src/OpenFOAM/db/IOstreams/token/tokenI.H index 33885121a6d..6b63aed010c 100644 --- a/src/OpenFOAM/db/IOstreams/token/tokenI.H +++ b/src/OpenFOAM/db/IOstreams/token/tokenI.H @@ -281,6 +281,11 @@ inline void Foam::token::reset() inline void Foam::token::swap(token& tok) { + if (this == &tok) + { + return; // Self-swap is a no-op + } + std::swap(data_, tok.data_); std::swap(type_, tok.type_); std::swap(lineNumber_, tok.lineNumber_); @@ -642,6 +647,11 @@ inline void Foam::token::setBad() inline void Foam::token::operator=(const token& tok) { + if (this == &tok) + { + return; // Self-assignment is a no-op + } + reset(); type_ = tok.type_; @@ -683,6 +693,11 @@ inline void Foam::token::operator=(const token& tok) inline void Foam::token::operator=(token&& tok) { + if (this == &tok) + { + return; // Self-assignment is a no-op + } + reset(); lineNumber_ = 0; swap(tok); diff --git a/src/OpenFOAM/db/dictionary/dictionary.C b/src/OpenFOAM/db/dictionary/dictionary.C index 10382ee8169..4b07aca7fc4 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.C +++ b/src/OpenFOAM/db/dictionary/dictionary.C @@ -876,7 +876,7 @@ bool Foam::dictionary::merge(const dictionary& dict) if (this == &dict) { FatalIOErrorInFunction(*this) - << "Attempted merge to self for dictionary " + << "Attempted merge to self, for dictionary " << name() << nl << abort(FatalIOError); } @@ -944,10 +944,7 @@ void Foam::dictionary::operator=(const dictionary& rhs) { if (this == &rhs) { - FatalIOErrorInFunction(*this) - << "Attempted assignment to self for dictionary " - << name() << nl - << abort(FatalIOError); + return; // Self-assignment is a no-op } name() = rhs.name(); @@ -968,7 +965,7 @@ void Foam::dictionary::operator+=(const dictionary& rhs) if (this == &rhs) { FatalIOErrorInFunction(*this) - << "Attempted addition assignment to self for dictionary " + << "Attempted addition to self, for dictionary " << name() << nl << abort(FatalIOError); } @@ -985,7 +982,7 @@ void Foam::dictionary::operator|=(const dictionary& rhs) if (this == &rhs) { FatalIOErrorInFunction(*this) - << "Attempted assignment to self for dictionary " + << "Attempted |= merging to self, for dictionary " << name() << nl << abort(FatalIOError); } @@ -1005,7 +1002,7 @@ void Foam::dictionary::operator<<=(const dictionary& rhs) if (this == &rhs) { FatalIOErrorInFunction(*this) - << "Attempted assignment to self for dictionary " + << "Attempted addition to self, for dictionary " << name() << nl << abort(FatalIOError); } diff --git a/src/OpenFOAM/db/dictionary/entry/entry.C b/src/OpenFOAM/db/dictionary/entry/entry.C index cb065eec764..3e5fe338773 100644 --- a/src/OpenFOAM/db/dictionary/entry/entry.C +++ b/src/OpenFOAM/db/dictionary/entry/entry.C @@ -179,12 +179,9 @@ void Foam::entry::checkITstream(const ITstream& is) const void Foam::entry::operator=(const entry& e) { - // check for assignment to self if (this == &e) { - FatalErrorInFunction - << "attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } keyword_ = e.keyword_; @@ -193,20 +190,24 @@ void Foam::entry::operator=(const entry& e) bool Foam::entry::operator==(const entry& e) const { + if (this == &e) + { + return true; + } if (keyword_ != e.keyword_) { return false; } - else - { - OStringStream oss1; - oss1 << *this; - OStringStream oss2; - oss2 << e; + // Compare contents (as strings) - return oss1.str() == oss2.str(); - } + OStringStream oss1; + oss1 << *this; + + OStringStream oss2; + oss2 << e; + + return oss1.str() == oss2.str(); } diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.C b/src/OpenFOAM/db/objectRegistry/objectRegistry.C index ed32f81a8bd..f6832dc47b4 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.C +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.C @@ -259,7 +259,7 @@ bool Foam::objectRegistry::checkIn(regIOobject* io) const if (!ok && objectRegistry::debug) { WarningInFunction - << name() << " : attempted to checkIn object with name " + << name() << " : Attempt to checkIn object with name " << io->name() << " which was already checked in" << endl; } @@ -291,7 +291,7 @@ bool Foam::objectRegistry::checkOut(regIOobject* io) const if (objectRegistry::debug) { WarningInFunction - << name() << " : attempt to checkOut copy of " + << name() << " : Attempt to checkOut copy of " << iter.key() << endl; } diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.C b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.C index 19f3542e679..17b50d374bb 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.C +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2015-2017 OpenCFD Ltd. + Copyright (C) 2015-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -492,12 +492,9 @@ void Foam::DimensionedField<Type, GeoMesh>::operator= const DimensionedField<Type, GeoMesh>& df ) { - // Check for assignment to self if (this == &df) { - FatalErrorInFunction - << "attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } checkField(*this, df, "="); @@ -516,12 +513,9 @@ void Foam::DimensionedField<Type, GeoMesh>::operator= { auto& df = tdf.constCast(); - // Check for assignment to self if (this == &df) { - FatalErrorInFunction - << "attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } checkField(*this, df, "="); diff --git a/src/OpenFOAM/fields/FieldFields/FieldField/FieldField.C b/src/OpenFOAM/fields/FieldFields/FieldField/FieldField.C index 17e38a80c9c..29f4fe8c215 100644 --- a/src/OpenFOAM/fields/FieldFields/FieldField/FieldField.C +++ b/src/OpenFOAM/fields/FieldFields/FieldField/FieldField.C @@ -292,10 +292,9 @@ void FieldField<Field, Type>::operator=(const FieldField<Field, Type>& ff) { if (this == &ff) { - FatalErrorInFunction - << "attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } + // No size checking done forAll(*this, i) @@ -310,9 +309,7 @@ void FieldField<Field, Type>::operator=(FieldField<Field, Type>&& ff) { if (this == &ff) { - FatalErrorInFunction - << "attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } PtrList<Field<Type>>::transfer(ff); @@ -325,9 +322,7 @@ void FieldField<Field, Type>::operator=(const tmp<FieldField>& tf) // The cref() method also checks that tmp is not nullptr. if (this == &(tf.cref())) { - FatalErrorInFunction - << "attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } PtrList<Field<Type>>::clear(); @@ -414,6 +409,6 @@ Ostream& operator<<(Ostream& os, const tmp<FieldField<Field, Type>>& tf) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - #include "FieldFieldFunctions.C" +#include "FieldFieldFunctions.C" // ************************************************************************* // diff --git a/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H b/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H index 53bc5b4944b..114480ba1b9 100644 --- a/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H +++ b/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H @@ -399,6 +399,11 @@ inline void Foam::DynamicField<T, SizeMin>::swap DynamicField<T, AnySizeMin>& lst ) { + if (this == &lst) + { + return; // Self-swap is a no-op + } + DynamicList<T, SizeMin>& cur = *this; // Make addressable size identical to the allocated capacity @@ -450,6 +455,11 @@ inline void Foam::DynamicField<T, SizeMin>::transfer DynamicField<T, AnySizeMin>& list ) { + if (this == &list) + { + return; // Self-assignment is a no-op + } + // Take over storage as-is (without shrink, without using SizeMin) // clear addressing and storage for old list. capacity_ = list.capacity(); @@ -484,7 +494,7 @@ Foam::DynamicField<T, SizeMin>::append if (this == &list) { FatalErrorInFunction - << "attempted appending to self" << abort(FatalError); + << "Attempted appending to self" << abort(FatalError); } label idx = List<T>::size(); @@ -563,8 +573,7 @@ inline void Foam::DynamicField<T, SizeMin>::operator= { if (this == &list) { - FatalErrorInFunction - << "Attempted assignment to self" << abort(FatalError); + return; // Self-assignment is a no-op } assignDynField(list); diff --git a/src/OpenFOAM/fields/Fields/Field/Field.C b/src/OpenFOAM/fields/Fields/Field/Field.C index 34095782375..549b6d850f1 100644 --- a/src/OpenFOAM/fields/Fields/Field/Field.C +++ b/src/OpenFOAM/fields/Fields/Field/Field.C @@ -656,9 +656,7 @@ void Foam::Field<Type>::operator=(const Field<Type>& rhs) { if (this == &rhs) { - FatalErrorInFunction - << "attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } List<Type>::operator=(rhs); @@ -670,9 +668,7 @@ void Foam::Field<Type>::operator=(const tmp<Field>& rhs) { if (this == &(rhs())) { - FatalErrorInFunction - << "attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } List<Type>::operator=(rhs()); diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C index df340d238fc..1b1c4866800 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C @@ -1327,9 +1327,7 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::operator= { if (this == &gf) { - FatalErrorInFunction - << "attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } checkField(*this, gf, "="); @@ -1351,9 +1349,7 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::operator= if (this == &gf) { - FatalErrorInFunction - << "attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } checkField(*this, gf, "="); diff --git a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrixOperations.C b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrixOperations.C index 5521b4f03e9..7524e15f06d 100644 --- a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrixOperations.C +++ b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrixOperations.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -170,9 +171,7 @@ void Foam::LduMatrix<Type, DType, LUType>::operator=(const LduMatrix& A) { if (this == &A) { - FatalErrorInFunction - << "attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } if (A.diagPtr_) diff --git a/src/OpenFOAM/matrices/Matrix/Matrix.C b/src/OpenFOAM/matrices/Matrix/Matrix.C index 94fc3ed55d9..b5ea2e4519d 100644 --- a/src/OpenFOAM/matrices/Matrix/Matrix.C +++ b/src/OpenFOAM/matrices/Matrix/Matrix.C @@ -289,6 +289,11 @@ Foam::List<Type> Foam::Matrix<Form, Type>::release() template<class Form, class Type> void Foam::Matrix<Form, Type>::swap(Matrix<Form, Type>& mat) { + if (this == &mat) + { + return; // Self-swap is a no-op + } + Foam::Swap(mRows_, mat.mRows_); Foam::Swap(nCols_, mat.nCols_); Foam::Swap(v_, mat.v_); @@ -298,6 +303,11 @@ void Foam::Matrix<Form, Type>::swap(Matrix<Form, Type>& mat) template<class Form, class Type> void Foam::Matrix<Form, Type>::transfer(Matrix<Form, Type>& mat) { + if (this == &mat) + { + return; // Self-assignment is a no-op + } + clear(); mRows_ = mat.mRows_; @@ -457,9 +467,7 @@ void Foam::Matrix<Form, Type>::operator=(const Matrix<Form, Type>& mat) { if (this == &mat) { - FatalErrorInFunction - << "Attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } if (mRows_ != mat.mRows_ || nCols_ != mat.nCols_) @@ -480,14 +488,11 @@ void Foam::Matrix<Form, Type>::operator=(const Matrix<Form, Type>& mat) template<class Form, class Type> void Foam::Matrix<Form, Type>::operator=(Matrix<Form, Type>&& mat) { - if (this == &mat) + if (this != &mat) { - FatalErrorInFunction - << "Attempted assignment to self" - << abort(FatalError); + // Self-assignment is a no-op + this->transfer(mat); } - - this->transfer(mat); } diff --git a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixOperations.C b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixOperations.C index 915f682b532..4d307f57100 100644 --- a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixOperations.C +++ b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixOperations.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -91,10 +92,7 @@ void Foam::lduMatrix::operator=(const lduMatrix& A) { if (this == &A) { - FatalError - << "lduMatrix::operator=(const lduMatrix&) : " - << "attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } if (A.lowerPtr_) diff --git a/src/OpenFOAM/matrices/simpleMatrix/simpleMatrix.C b/src/OpenFOAM/matrices/simpleMatrix/simpleMatrix.C index d9d531d639e..693a33ff015 100644 --- a/src/OpenFOAM/matrices/simpleMatrix/simpleMatrix.C +++ b/src/OpenFOAM/matrices/simpleMatrix/simpleMatrix.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -103,9 +104,7 @@ void Foam::simpleMatrix<Type>::operator=(const simpleMatrix<Type>& m) { if (this == &m) { - FatalErrorInFunction - << "Attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } if (m() != m.m()) diff --git a/src/OpenFOAM/memory/autoPtr/autoPtrI.H b/src/OpenFOAM/memory/autoPtr/autoPtrI.H index 7b536a0fc99..ba1eb5b93ee 100644 --- a/src/OpenFOAM/memory/autoPtr/autoPtrI.H +++ b/src/OpenFOAM/memory/autoPtr/autoPtrI.H @@ -172,6 +172,7 @@ inline void Foam::autoPtr<T>::reset(autoPtr<T>&& ap) noexcept template<class T> inline void Foam::autoPtr<T>::swap(autoPtr<T>& other) noexcept { + // Self-swap is effectively ignored T* p = ptr_; ptr_ = other.ptr_; other.ptr_ = p; @@ -259,6 +260,7 @@ inline void Foam::autoPtr<T>::operator=(autoPtr<T>&& ap) noexcept { if (this != &ap) { + // Ignore self-assignment reset(ap.release()); } } @@ -270,6 +272,7 @@ inline void Foam::autoPtr<T>::operator=(autoPtr<U>&& ap) noexcept { if (this != &ap) { + // Ignore self-assignment reset(ap.release()); } } diff --git a/src/OpenFOAM/memory/tmp/tmpI.H b/src/OpenFOAM/memory/tmp/tmpI.H index 261472c6a02..21e30caf6ff 100644 --- a/src/OpenFOAM/memory/tmp/tmpI.H +++ b/src/OpenFOAM/memory/tmp/tmpI.H @@ -369,6 +369,11 @@ inline void Foam::tmp<T>::cref(const T& obj) noexcept template<class T> inline void Foam::tmp<T>::swap(tmp<T>& other) noexcept { + if (&other == this) + { + return; // Self-swap is a no-op + } + // Copy/assign for pointer types T* p = ptr_; ptr_ = other.ptr_; @@ -460,6 +465,11 @@ inline void Foam::tmp<T>::operator=(T* p) template<class T> inline void Foam::tmp<T>::operator=(const tmp<T>& t) { + if (&t == this) + { + return; // Self-assignment is a no-op + } + clear(); if (t.isTmp()) diff --git a/src/OpenFOAM/memory/tmp/tmpNrcI.H b/src/OpenFOAM/memory/tmp/tmpNrcI.H index b6a1e7a1a18..fd35c741ef7 100644 --- a/src/OpenFOAM/memory/tmp/tmpNrcI.H +++ b/src/OpenFOAM/memory/tmp/tmpNrcI.H @@ -319,6 +319,11 @@ inline void Foam::tmpNrc<T>::cref(const T& obj) noexcept template<class T> inline void Foam::tmpNrc<T>::swap(tmpNrc<T>& other) noexcept { + if (&other == this) + { + return; // Self-swap is a no-op + } + // Copy/assign for pointer types T* p = ptr_; ptr_ = other.ptr_; @@ -403,6 +408,11 @@ inline void Foam::tmpNrc<T>::operator=(T* p) template<class T> inline void Foam::tmpNrc<T>::operator=(const tmpNrc<T>& t) { + if (&t == this) + { + return; // Self-assignment is a no-op + } + clear(); if (t.isTmp()) diff --git a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistribute.C b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistribute.C index 6e4eee7fcb7..5551bcc0b47 100644 --- a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistribute.C +++ b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistribute.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2015-2018 OpenCFD Ltd. + Copyright (C) 2015-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -516,6 +516,11 @@ Foam::label Foam::mapDistribute::whichTransform(const label index) const void Foam::mapDistribute::transfer(mapDistribute& rhs) { + if (this == &rhs) + { + // Self-assignment is a no-op + } + mapDistributeBase::transfer(rhs); transformElements_.transfer(rhs.transformElements_); transformStart_.transfer(rhs.transformStart_); @@ -528,11 +533,9 @@ void Foam::mapDistribute::operator=(const mapDistribute& rhs) { if (this == &rhs) { - // Avoid self-assignment - FatalErrorInFunction - << "Attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } + mapDistributeBase::operator=(rhs); transformElements_ = rhs.transformElements_; transformStart_ = rhs.transformStart_; diff --git a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBase.C b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBase.C index d5bbcab8a7e..a5af2224a43 100644 --- a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBase.C +++ b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBase.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2015-2017 OpenFOAM Foundation - Copyright (C) 2015-2016, OpenCFD Ltd. + Copyright (C) 2015-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -839,6 +839,12 @@ Foam::mapDistributeBase::mapDistributeBase(Istream& is) void Foam::mapDistributeBase::transfer(mapDistributeBase& rhs) { + if (this == &rhs) + { + // Self-assignment is a no-op + return; + } + constructSize_ = rhs.constructSize_; subMap_.transfer(rhs.subMap_); constructMap_.transfer(rhs.constructMap_); @@ -1264,11 +1270,9 @@ void Foam::mapDistributeBase::operator=(const mapDistributeBase& rhs) { if (this == &rhs) { - // Avoid self assignment - FatalErrorInFunction - << "Attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } + constructSize_ = rhs.constructSize_; subMap_ = rhs.subMap_; constructMap_ = rhs.constructMap_; diff --git a/src/OpenFOAM/primitives/strings/keyType/keyTypeI.H b/src/OpenFOAM/primitives/strings/keyType/keyTypeI.H index 8c1d8fa6806..cbf710e5170 100644 --- a/src/OpenFOAM/primitives/strings/keyType/keyTypeI.H +++ b/src/OpenFOAM/primitives/strings/keyType/keyTypeI.H @@ -170,10 +170,9 @@ inline void Foam::keyType::clear() inline void Foam::keyType::swap(keyType& s) { - // Self-swapping is a no-op if (this == &s) { - return; + return; // Self-swap is a no-op } word::swap(static_cast<word&>(s)); @@ -191,10 +190,9 @@ inline bool Foam::keyType::operator()(const std::string& text) const inline void Foam::keyType::operator=(const keyType& s) { - // Self-assignment is a no-op if (this == &s) { - return; + return; // Self-assignment is a no-op } assign(s); // Bypasses char checking @@ -204,10 +202,9 @@ inline void Foam::keyType::operator=(const keyType& s) inline void Foam::keyType::operator=(keyType&& s) { - // Self-assignment is a no-op if (this == &s) { - return; + return; // Self-assignment is a no-op } clear(); diff --git a/src/OpenFOAM/primitives/strings/lists/hashedWordListI.H b/src/OpenFOAM/primitives/strings/lists/hashedWordListI.H index bb20a176391..17ab7f32387 100644 --- a/src/OpenFOAM/primitives/strings/lists/hashedWordListI.H +++ b/src/OpenFOAM/primitives/strings/lists/hashedWordListI.H @@ -146,6 +146,11 @@ inline bool Foam::hashedWordList::found(const word& name) const inline void Foam::hashedWordList::swap(hashedWordList& list) { + if (this == &list) + { + return; // Self-swap is a no-op + } + wordList::swap(static_cast<wordList&>(list)); lookup_.swap(list.lookup_); } diff --git a/src/OpenFOAM/primitives/strings/regex/regExpCxxI.H b/src/OpenFOAM/primitives/strings/regex/regExpCxxI.H index 4e2b3b81492..1c68adb20f2 100644 --- a/src/OpenFOAM/primitives/strings/regex/regExpCxxI.H +++ b/src/OpenFOAM/primitives/strings/regex/regExpCxxI.H @@ -154,8 +154,12 @@ inline bool Foam::regExpCxx::clear() inline void Foam::regExpCxx::swap(regExpCxx& rgx) { - re_.swap(rgx.re_); - std::swap(ok_, rgx.ok_); + if (this != &rgx) + { + // Self-swap is a no-op + re_.swap(rgx.re_); + std::swap(ok_, rgx.ok_); + } } diff --git a/src/OpenFOAM/primitives/strings/string/stringI.H b/src/OpenFOAM/primitives/strings/string/stringI.H index 19ce1f98188..a5e890749ec 100644 --- a/src/OpenFOAM/primitives/strings/string/stringI.H +++ b/src/OpenFOAM/primitives/strings/string/stringI.H @@ -265,9 +265,9 @@ inline bool Foam::string::match(const std::string& text) const inline void Foam::string::swap(std::string& str) { - // Self-swapping is a no-op if (this != &str) { + // Self-swap is a no-op std::string::swap(str); } } diff --git a/src/OpenFOAM/primitives/strings/wordRe/wordReI.H b/src/OpenFOAM/primitives/strings/wordRe/wordReI.H index f008f4794fa..9d09b771d0e 100644 --- a/src/OpenFOAM/primitives/strings/wordRe/wordReI.H +++ b/src/OpenFOAM/primitives/strings/wordRe/wordReI.H @@ -259,10 +259,9 @@ inline void Foam::wordRe::set(const char* str, const compOption opt) inline void Foam::wordRe::swap(wordRe& str) { - // Self-swapping is a no-op if (this == &str) { - return; + return; // Self-swap is a no-op } word::swap(static_cast<word&>(str)); @@ -280,10 +279,9 @@ inline bool Foam::wordRe::operator()(const std::string& text) const inline void Foam::wordRe::operator=(const wordRe& str) { - // Self-assignment is a no-op if (this == &str) { - return; + return; // Self-assignment is a no-op } assign(str); @@ -342,10 +340,9 @@ inline void Foam::wordRe::operator=(const char* str) inline void Foam::wordRe::operator=(wordRe&& str) { - // Self-assignment is a no-op if (this == &str) { - return; + return; // Self-assignment is a no-op } clear(); diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/refinementHistory.C b/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/refinementHistory.C index 10cea017c2a..11b98c08c17 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/refinementHistory.C +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/refinementHistory.C @@ -147,12 +147,9 @@ void Foam::refinementHistory::splitCell8::operator=(const splitCell8& s) { // Assignment operator since autoPtr otherwise 'steals' storage. - // Check for assignment to self if (this == &s) { - FatalErrorInFunction - << "Attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } parent_ = s.parent_; diff --git a/src/finiteArea/faMatrices/faMatrix/faMatrix.C b/src/finiteArea/faMatrices/faMatrix/faMatrix.C index 5a80f21dd6b..eef14bd5b0b 100644 --- a/src/finiteArea/faMatrices/faMatrix/faMatrix.C +++ b/src/finiteArea/faMatrices/faMatrix/faMatrix.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2016-2017 Wikki Ltd + Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -712,9 +713,7 @@ void Foam::faMatrix<Type>::operator=(const faMatrix<Type>& famv) { if (this == &famv) { - FatalErrorInFunction - << "attempted to assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } if (&psi_ != &(famv.psi_)) diff --git a/src/finiteVolume/finiteVolume/convectionSchemes/convectionScheme/convectionScheme.C b/src/finiteVolume/finiteVolume/convectionSchemes/convectionScheme/convectionScheme.C index 4b3f41b6fec..f21e3254db3 100644 --- a/src/finiteVolume/finiteVolume/convectionSchemes/convectionScheme/convectionScheme.C +++ b/src/finiteVolume/finiteVolume/convectionSchemes/convectionScheme/convectionScheme.C @@ -159,9 +159,7 @@ void convectionScheme<Type>::operator=(const convectionScheme<Type>& cs) { if (this == &cs) { - FatalErrorInFunction - << "attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } } diff --git a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C index e08e91f6e4f..1aeeb961e09 100644 --- a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C +++ b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2016 OpenCFD Ltd. + Copyright (C) 2016-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -1031,9 +1031,7 @@ void Foam::fvMatrix<Type>::operator=(const fvMatrix<Type>& fvmv) { if (this == &fvmv) { - FatalErrorInFunction - << "attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } if (&psi_ != &(fvmv.psi_)) diff --git a/src/functionObjects/field/fieldAverage/fieldAverageItem/fieldAverageItem.C b/src/functionObjects/field/fieldAverage/fieldAverageItem/fieldAverageItem.C index 850ed93d071..6396c135471 100644 --- a/src/functionObjects/field/fieldAverage/fieldAverageItem/fieldAverageItem.C +++ b/src/functionObjects/field/fieldAverage/fieldAverageItem/fieldAverageItem.C @@ -228,12 +228,9 @@ void Foam::functionObjects::fieldAverageItem::operator= const fieldAverageItem& rhs ) { - // Check for assignment to self if (this == &rhs) { - FatalErrorInFunction - << "Attempted assignment to self" << nl - << abort(FatalError); + return; // Self-assignment is a no-op } // Set updated values diff --git a/src/lagrangian/intermediate/parcels/Templates/CollidingParcel/CollisionRecordList/CollisionRecordList.C b/src/lagrangian/intermediate/parcels/Templates/CollidingParcel/CollisionRecordList/CollisionRecordList.C index bbc7a9dcef2..fecdcb91776 100644 --- a/src/lagrangian/intermediate/parcels/Templates/CollidingParcel/CollisionRecordList/CollisionRecordList.C +++ b/src/lagrangian/intermediate/parcels/Templates/CollidingParcel/CollisionRecordList/CollisionRecordList.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -393,12 +394,9 @@ void Foam::CollisionRecordList<PairType, WallType>::operator= const CollisionRecordList<PairType, WallType>& rhs ) { - // Check for assignment to self if (this == &rhs) { - FatalErrorInFunction - << "Attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } pairRecords_ = rhs.pairRecords_; diff --git a/src/lagrangian/intermediate/parcels/Templates/CollidingParcel/CollisionRecordList/PairCollisionRecord/PairCollisionRecord.C b/src/lagrangian/intermediate/parcels/Templates/CollidingParcel/CollisionRecordList/PairCollisionRecord/PairCollisionRecord.C index e96f8f87cb6..e6d921c7f16 100644 --- a/src/lagrangian/intermediate/parcels/Templates/CollidingParcel/CollisionRecordList/PairCollisionRecord/PairCollisionRecord.C +++ b/src/lagrangian/intermediate/parcels/Templates/CollidingParcel/CollisionRecordList/PairCollisionRecord/PairCollisionRecord.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -87,12 +88,9 @@ void Foam::PairCollisionRecord<Type>::operator= const PairCollisionRecord<Type>& rhs ) { - // Check for assignment to self if (this == &rhs) { - FatalErrorInFunction - << "Attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } origProcOfOther_ = rhs.origProcOfOther_; diff --git a/src/lagrangian/intermediate/parcels/Templates/CollidingParcel/CollisionRecordList/WallCollisionRecord/WallCollisionRecord.C b/src/lagrangian/intermediate/parcels/Templates/CollidingParcel/CollisionRecordList/WallCollisionRecord/WallCollisionRecord.C index a6073dfb8f4..581828a593d 100644 --- a/src/lagrangian/intermediate/parcels/Templates/CollidingParcel/CollisionRecordList/WallCollisionRecord/WallCollisionRecord.C +++ b/src/lagrangian/intermediate/parcels/Templates/CollidingParcel/CollisionRecordList/WallCollisionRecord/WallCollisionRecord.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -85,12 +86,9 @@ void Foam::WallCollisionRecord<Type>::operator= const WallCollisionRecord<Type>& rhs ) { - // Check for assignment to self if (this == &rhs) { - FatalErrorInFunction - << "Attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } accessed_ = rhs.accessed_; diff --git a/src/lagrangian/molecularDynamics/molecularMeasurements/bufferedAccumulator/bufferedAccumulator.C b/src/lagrangian/molecularDynamics/molecularMeasurements/bufferedAccumulator/bufferedAccumulator.C index a2954a60ae3..42b88a90ba2 100644 --- a/src/lagrangian/molecularDynamics/molecularMeasurements/bufferedAccumulator/bufferedAccumulator.C +++ b/src/lagrangian/molecularDynamics/molecularMeasurements/bufferedAccumulator/bufferedAccumulator.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -211,12 +212,9 @@ void Foam::bufferedAccumulator<Type>::operator= const bufferedAccumulator<Type>& rhs ) { - // Check for assignment to self if (this == &rhs) { - FatalErrorInFunction - << "Attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } List<Field<Type>>::operator=(rhs); @@ -229,6 +227,6 @@ void Foam::bufferedAccumulator<Type>::operator= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - #include "bufferedAccumulatorIO.C" +#include "bufferedAccumulatorIO.C" // ************************************************************************* // diff --git a/src/lagrangian/molecularDynamics/molecularMeasurements/distribution/distribution.C b/src/lagrangian/molecularDynamics/molecularMeasurements/distribution/distribution.C index 26078ed7414..1cf639b836b 100644 --- a/src/lagrangian/molecularDynamics/molecularMeasurements/distribution/distribution.C +++ b/src/lagrangian/molecularDynamics/molecularMeasurements/distribution/distribution.C @@ -432,12 +432,9 @@ Foam::List<Foam::Pair<Foam::scalar>> Foam::distribution::raw() void Foam::distribution::operator=(const distribution& rhs) { - // Check for assignment to self if (this == &rhs) { - FatalErrorInFunction - << "Attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } Map<label>::operator=(rhs); diff --git a/src/meshTools/triSurface/surfaceFeatures/surfaceFeatures.C b/src/meshTools/triSurface/surfaceFeatures/surfaceFeatures.C index eca7f56c31d..11053f5ad1d 100644 --- a/src/meshTools/triSurface/surfaceFeatures/surfaceFeatures.C +++ b/src/meshTools/triSurface/surfaceFeatures/surfaceFeatures.C @@ -1805,12 +1805,9 @@ void Foam::surfaceFeatures::nearestFeatEdge void Foam::surfaceFeatures::operator=(const surfaceFeatures& rhs) { - // Check for assignment to self if (this == &rhs) { - FatalErrorInFunction - << "Attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } if (&surf_ != &rhs.surface()) diff --git a/src/sampling/surface/cutting/cuttingPlane.C b/src/sampling/surface/cutting/cuttingPlane.C index 15cdde491c8..15a773ae526 100644 --- a/src/sampling/surface/cutting/cuttingPlane.C +++ b/src/sampling/surface/cutting/cuttingPlane.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -150,9 +150,7 @@ void Foam::cuttingPlane::operator=(const cuttingPlane& rhs) { if (this == &rhs) { - FatalErrorInFunction - << "Attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } static_cast<MeshStorage&>(*this) = rhs; diff --git a/src/sampling/surface/cutting/cuttingSurfaceBase.C b/src/sampling/surface/cutting/cuttingSurfaceBase.C index 85036084915..a207e3ae368 100644 --- a/src/sampling/surface/cutting/cuttingSurfaceBase.C +++ b/src/sampling/surface/cutting/cuttingSurfaceBase.C @@ -98,9 +98,7 @@ void Foam::cuttingSurfaceBase::operator=(const cuttingSurfaceBase& rhs) { if (this == &rhs) { - FatalErrorInFunction - << "Attempted assignment to self" - << abort(FatalError); + return; // Self-assignment is a no-op } static_cast<MeshStorage&>(*this) = rhs; diff --git a/src/surfMesh/MeshedSurface/MeshedSurface.C b/src/surfMesh/MeshedSurface/MeshedSurface.C index 34750f135f9..c9b491e330a 100644 --- a/src/surfMesh/MeshedSurface/MeshedSurface.C +++ b/src/surfMesh/MeshedSurface/MeshedSurface.C @@ -1109,6 +1109,11 @@ void Foam::MeshedSurface<Face>::swap MeshedSurface<Face>& surf ) { + if (this == &surf) + { + return; // Self-swap is a no-op + } + ParentType::clearOut(); // Topology changes surf.clearOut(); // Topology changes @@ -1139,6 +1144,11 @@ void Foam::MeshedSurface<Face>::transfer MeshedSurface<Face>& surf ) { + if (this == &surf) + { + return; // Self-assigment is a no-op + } + ParentType::clearOut(); // Topology changes this->storedPoints().transfer(surf.storedPoints()); diff --git a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C index 9b857d7e300..4fc6ff9b16b 100644 --- a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C +++ b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C @@ -603,6 +603,11 @@ void Foam::UnsortedMeshedSurface<Face>::swap UnsortedMeshedSurface<Face>& surf ) { + if (this == &surf) + { + return; // Self-swap is a no-op + } + this->clearOut(); // Topology changes surf.clearOut(); // Topology changes @@ -622,6 +627,11 @@ void Foam::UnsortedMeshedSurface<Face>::transfer UnsortedMeshedSurface<Face>& surf ) { + if (this == &surf) + { + return; // Self-assignment is a no-op + } + this->clear(); this->storedPoints().transfer(surf.storedPoints()); diff --git a/src/surfMesh/triSurface/triSurface.C b/src/surfMesh/triSurface/triSurface.C index 36bb8fcdc10..69cf3036f7b 100644 --- a/src/surfMesh/triSurface/triSurface.C +++ b/src/surfMesh/triSurface/triSurface.C @@ -549,6 +549,11 @@ void Foam::triSurface::clearOut() void Foam::triSurface::swap(triSurface& surf) { + if (this == &surf) + { + return; // Self-swap is a no-op + } + clearOut(); surf.clearOut(); -- GitLab