fix move special functions in mem in and outfile#258
Merged
aous72 merged 1 commit intoaous72:masterfrom Feb 25, 2026
Merged
Conversation
Owner
|
Thank you putting an eye on the code, and for correcting it -- the code has to be correct. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Dear Aous,
I'm sorry I have to bother you with this again. Some changes were made to my last pull request that introduced a hard to see, but critical bug. In the move constructors a call to
std::swapis performed which leads to an infinite recursion and stack overflow. The problem is that currentlystd::swapis now used with an argument of typemem_outfilein themem_outfilemove constructor. This will lead to infinite recursion, becausestd::swapitself uses the move constructor and move assignment of themem_outfileclass itself. Allow me to explain:As an example, the version of the gnu standard library that I'm using defines
std::moveas:which roughly simplifies to
From this, we can see that calling
std::swaplike is currently done is a problem. It's of course fine to callstd::swapon the member fields themselves, but not on the instance of the class itself.I'm pretty sure this is the reason that the late C++ expert Rainer Grimm writes here
We can also infer from the documentation on
std::swapon cppreference, that the use of the move constructor and assignment is not particular to glibcxx, but is actually part of the standard:This isn't well-defined unless the move constructor is defined without the use of std::swap.