Fix polynomial.hpp deprecated-copy warnings#111
Open
jcstroud wants to merge 1 commit intoboostorg:developfrom
Open
Fix polynomial.hpp deprecated-copy warnings#111jcstroud wants to merge 1 commit intoboostorg:developfrom
jcstroud wants to merge 1 commit intoboostorg:developfrom
Conversation
# Fixed Deprecated Copy Constructor Warning in `polynomial.hpp`
## Issue Description
The `boost/random/detail/polynomial.hpp` triggers compiler warnings related to a deprecated implicit copy constructor:
```
warning: definition of implicit copy constructor for 'reference' is deprecated because it has a user-declared copy assignment operator [-Wdeprecated-copy]
```
This warning occurs in C++11 and later standards when a class has a user-declared copy assignment operator but no user-declared copy constructor.
## Cause
The `reference` class has a user-declared copy assignment operator:
```cpp
reference &operator=(const reference &other)
```
However, this reference class lacks an explicitly declared copy constructor.
## Backwards-Compatible Fix
To ensure maximum compatibility with various compiler versions, including older ones, we've implemented the following changes:
1. Explicitly defined a copy constructor that performs a member-wise copy. This silences the deprecation warning while maintaining the original behavior:
```cpp reference(const reference& other) : _value(other._value), _idx(other._idx) {} ```
2. Omitted the move constructor, ensuring compatibility with pre-C++11 compilers while not affecting functionality. In C++11 and later, moves will be performed as copies, maintaining original behavior.
## Impact of the Fix
This fix resolves the compiler warnings without changing the functionality of the `reference` class.
The fix is backwards-compatible and should not introduce any behavioral changes in existing code.
## Conclusion
This update brings the `polynomial.hpp` file in line with current C++ standards and best practices. It eliminates deprecation warnings while maintaining existing functionality.
Author
|
For future reference, a C++11 version of this request can be found here: #110 |
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.
Fixed Deprecated Copy Constructor Warning in
polynomial.hppIssue Description
The
boost/random/detail/polynomial.hpptriggers compiler warnings related to a deprecated implicit copy constructor:This warning occurs in C++11 and later standards when a class has a user-declared copy assignment operator but no user-declared copy constructor.
Cause
The
referenceclass has a user-declared copy assignment operator:However, this reference class lacks an explicitly declared copy constructor.
Backwards-Compatible Fix
To ensure maximum compatibility with various compiler versions, including older ones, we've implemented the following changes:
Explicitly defined a copy constructor that performs a member-wise copy. This silences the deprecation warning while maintaining the original behavior:
cpp reference(const reference& other) : _value(other._value), _idx(other._idx) {}Omitted the move constructor, ensuring compatibility with pre-C++11 compilers while not affecting functionality. In C++11 and later, moves will be performed as copies, maintaining original behavior.
Impact of the Fix
This fix resolves the compiler warnings without changing the functionality of the
referenceclass.The fix is backwards-compatible and should not introduce any behavioral changes in existing code.
Conclusion
This update brings the
polynomial.hppfile in line with current C++ standards and best practices. It eliminates deprecation warnings while maintaining existing functionality.