Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix polynomial.hpp deprecated-copy warnings #111

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

jcstroud
Copy link

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:

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.

# 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.
@jcstroud
Copy link
Author

For future reference, a C++11 version of this request can be found here: #110

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant