diff --git a/etc/codeTemplates/source/_Template.C b/etc/codeTemplates/source/_Template.C index c8f231a79e33a554d83d90fac8e98bdeef039d32..8708db050386b5d4edb7840aae64ec47e7f2487d 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 9c5c3caa9712f43af04b7e13e8e9ca5352bc06b8..8adec14c3900a9a626657885d617abdd6c50d7a2 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 60cf6d9e5c96329d815c77ff049c4835fd877bdf..3d8df849af2a94580c3e6e484bb7acdcaf55b1d2 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 4919d62568c3e0f43a0977d4f8d95d8bee6bfc4c..4fe51d14e863b2c9146d3457dbc4e52ba5b68dbf 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 161f68c60b04c013813ba82fa4d948fb7714e886..c3332a4a2f19a1b7d6a65918ec62cf139461cff5 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 9da7624c223af1c381de85352bc592fdff10eeb6..88aa28fe42a2ff2aa923d3542f43ce52316da56b 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 7c8ed24f3f3b5e3923ad92fbc633c80993a1715c..fded93cc55e1b53a00a7135d972a80e83a591465 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 a2f73e1828149d36ad949fb44cd46b8773b65d9e..e2df5eb424e4c68f190d57c15767a9cf1ff8808c 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 8f93c5f3d7db3fc1eb3e3e4317d836e8da4db034..c8a8fffed5e02b825c5b6fe90f68472e62a943b2 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 d2b0c45f6f3419539502f1d4a30ce6bbbfff255e..17d0121bfc341518f089b61801d0f586bf28dfb9 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 13d1d7b4d7947bd9ec0ee6522698fc089d2d4df8..02cafc82b056d5b9bb2b5c43f7ddd1d0019ccfee 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 42c08708c6cb1d93eb2e549acdce14579a8f9ef5..d9a44565217b7d555a7cb05f8586d096ec88693e 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 d837f41b9fcfe6697ba7ac7211e4a510e81bd1a5..f2fbd29724d82361795fe2811d71f41f739109ba 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 ff79c865be3c7de31b2a72198e8d73feafc06f28..1a3c2613abc52765f4e6d54364335b824971164a 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 19b29270f91bd050f59758df20a22be4cbd56a91..1e5d2e541b6b2c0669d68af35036df3bbb5bfb18 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 d74bc281db1402cca0e4dd519b03768f9d26e49b..6b71e10211cef4a65fccdedd93e6557e296020e2 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 d6e5f62bc618b68d351a03501e004d7cdd677557..47057ec99571f00790cd92faa62d64c83d92d441 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 d91dcc8794622422a6f51a66e33ba10f1291faa3..426efed774e9985bc9f7d218af3e0aece10cc641 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 b6e2d2f990ad908aa02654260e7cfca211a33ee9..c32eef539483136679ccd94a7b887296571eb171 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 817e9c00d05a388abc1d477ad246bc94950119b3..4d3d755a2fd94bb5c439dc338d65265b80024e9c 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 8066626e6507c22894837cee24512bd3a9522de5..4a8452487f704df2ccaca010d1b77f1693074914 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 b3045ad2535981a8cea86b544c686460974eb567..d6845719d8ad938b4257ce4de824dca7374c9c78 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 b75abd5366a83045654836154ce3b9224a9eeb78..7df86c8da32796109dd95c3571b0a11fbabe4507 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 2d56f368bb969225cf1d24669e520b9d48a967c3..6c29a834a799863700c43c8857d5eabbbbe4bf89 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 2763bcdfb13a685e2a46ced8befc80873243fcb8..c7ab9b7ac9a5bd81ada0429e31945926fc7987eb 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 c13cf8ccd73ed0008260501d5ddb22c74884d1b6..cfd3507fca2653df6cae956057c9c8cf37c59df8 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 33885121a6dfd7c12b962ff4b1b69b8a9dfb7f7c..6b63aed010c3c15ca884b733bb8b0550279bd0ae 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 10382ee81696160ce50a7c3bd5009324e2dbb1e4..4b07aca7fc419d2390b289c979ab99c43cd1b8eb 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 cb065eec76411201baf7b1b039e3765785a114de..3e5fe3387736447922267c1319c77e6b144608bc 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 ed32f81a8bdf56e5ee7b950283b39a387e416e5d..f6832dc47b4d1c115dcbad6d11e6b1af9854fedb 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 19f3542e6796a57b7dce3890d7b4b6b07aeb9c4c..17b50d374bb0c349de0c92ef2fbfc7686c5792f7 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 17e38a80c9c9d5a8e062581b102b0a8f51abbf65..29f4fe8c2156abefe4917e72a9c0ae708266ac04 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 53bc5b4944b21cbd247adfb39eddddf96a0bfb78..114480ba1b9a131502113b3ea6acf6f6d1d4b1f5 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 340957823758e14b59338ab712acb4c2bb5a8494..549b6d850f1ebe11cc38dcd04c26d2fa7717639f 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 df340d238fcae0ff3a415c53e1fafb24811e5329..1b1c486680056493ca58b3fab5e92a8bafd269f8 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 5521b4f03e9afebf2cac627a5164b809a79c381d..7524e15f06dba3b22c47fe37c63ad7e7101b8800 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 94fc3ed55d9f53d767bf45d9748f2b5c97eebb9f..b5ea2e4519d84f1b3cc700ab9c836ffd28cea19a 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 915f682b532c2eb27a39200526fbb562ae87ea91..4d307f57100f385789528a2a34001fa70f0f4217 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 d9d531d639eeedbf4608257dbad2216de64d9b9f..693a33ff015abbcd62b409dffcbe4fbbde8a6b44 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 7b536a0fc99bed989b43666ec8d4829c832fe74b..ba1eb5b93eea257d6bb97c15d2c885e04d82c5e6 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 261472c6a02b69ff10d56cf6f8f95ace9bc3a26f..21e30caf6ffd61be499417574243e66d7f8c6b19 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 b6a1e7a1a183cdf1afacc48bed44862c864eff02..fd35c741ef76280a7c98338cc973cc453216031d 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 6e4eee7fcb79cb4aca8c5e7ceca1c50efb48f086..5551bcc0b471879b7edcb685acafab71f9b42f25 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 d5bbcab8a7e9412fd28ebb5481886ad734b32ee9..a5af2224a43062e00c8bea1d2ee9597af51b96cb 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 8c1d8fa68069004294e1e378d41c753ab91ac944..cbf710e51709910b48c96c2fa5a34bec80082b66 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 bb20a17639156c3148e24dea130a8b578236880e..17ab7f323870e5c40991b4fc69d713efba6579bf 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 4e2b3b8149250336f487635219d227132fbff4a2..1c68adb20f2785b367dd4bc35240f3a49924b0b7 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 19ce1f98188ddfe8f7bd80db6033aec209c9ff6e..a5e890749ecf7e3d81750ef98a30fd2e1550528b 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 f008f4794fad3b6f8477d99ec275e4b4dfcd1ecc..9d09b771d0e5d137d039dbda81796cbc0f173f4e 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 10cea017c2ad3ed4ba340ab31ee6d62a50b14db5..11b98c08c179973bf3b7ac24e69c9218ad65b2b4 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 5a80f21dd6b288794eb4b03ac0c272ca2fb62fb6..eef14bd5b0be44cad16a5a3530a0658751d9785a 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 4b3f41b6fece3b195139b4df712189321f67eca5..f21e3254db313a4dc0c4c89da19e44ea9c130566 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 e08e91f6e4f026cb1acc64dd1fe80404374f81a3..1aeeb961e0985ef1c3a4a7c3c12f92d1f5d138a4 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 850ed93d07141bc4c2c094f4331d120fc0c49c28..6396c13547182b8f79be7079c3d3a8a40763a2c0 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 bbc7a9dcef27a8311e4d3320830e73935f9b3f33..fecdcb91776701314b4d516f73974d9a02cd7b47 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 e96f8f87cb60693f1980ed5015cf5870d412596b..e6d921c7f1677417d3da8a246c01c10e66bf6d28 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 a6073dfb8f4740b0242b1d2976497c9ad32ccd78..581828a593df4e36e02215cd1b431360c283c7b9 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 a2954a60ae3b25661c049d22d0b1e8f965b39b4e..42b88a90ba22736c2e5908659f19176affbb756e 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 26078ed7414b95e4a2fa40ce3d52e3336dc97446..1cf639b836b016f2d21b05fe8e105c14f8b28ddf 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 eca7f56c31d1087ae96599f671b43daa1e3109d9..11053f5ad1d2179efc5af37be136c795296efde2 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 15cdde491c8056bb9c3d407dcf79344acbd32262..15a773ae526a2cb1b38fd05d8e19b4a2c0ff85e3 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 8503608491532e9437c7697b15986f2a25b5c3af..a207e3ae3681c975dca8910293e0d5908bc25092 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 34750f135f99a66de72fadde278907b26abe63f8..c9b491e330a46295cb18a4e4ad1016f54b3da6cf 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 9b857d7e300f2b94d77197f2acdb879a3db54982..4fc6ff9b16b9bc99694066b9442b925e2a76aaf5 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 36bb8fcdc108c0db5fe5d31b48c0ff120dd063ba..69cf3036f7b7133660b8efb50e35da0c15dcd74d 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();