Fix: Assignment to const
results in a "no overload" error for operator=
#9
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.
On some platforms, an assignment to a
const mpz_class
results in a "no overload" error foroperator=
(assignment operator). The error is triggered when it is not true thatSIZEOF_UNSIGNED_LONG == 8
, e.g. on 32-bit architectures.The context is small enough to reproduce in its entirety here:
It looks like just a copy+paste error, because
number
doesn't need to beconst
here. Excruciating details are given in the next paragraph, which you're welcome to skip over.The issue is in the
#else
preprocessor branch, where it is assumed thatunsigned long
is 32 bits. The "hack" is to load the value of the 64-bit parameternat
into anmpz_class
number
32 bits at a time by first loading the high 32 bits into the lower 32 bits ofnumber
, shiftingnumber
left by 32, and then loading the low 32 bits ofnat
into the now zeroed lower 32 bits ofnumber
. These steps require at least two assignments tonumber
, which is prohibited by theconst
.The fix is to remove the
const
.