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

Removes implicit conversions in std::complex #84

Closed
wants to merge 1 commit into from

Conversation

weslleyspereira
Copy link

std::complex<_Tp> assumes that int, double, long double are explicitly convertible to _Tp. Currently, std::complex<_Tp> also assumes that:

  1. int is implicitly convertible to _Tp, e.g., when using complex<_Tp>(1).
  2. long double can be attributed to a _Tp variable, e.g., when using const _Tp __pi_2 = 1.5707963267948966192313216916397514L.

This PR removes assumptions (1) and (2), broadening the types std::complex supports. One example is the type Eigen::Half in https://eigen.tuxfamily.org/dox-devel/Half_8h_source.html. This type does not implement implicit conversions.

`std::complex<_Tp>` assumes that `int, double, long double` are explicitly convertible to `_Tp`. Currently, `std::complex<_Tp>` also assumes that:
1. `int` is implicitly convertible to `_Tp`, e.g., when using `complex<_Tp>(1)`.
2. `long double` can be attributed to a `_Tp` variable, e.g., when using `const _Tp __pi_2 = 1.5707963267948966192313216916397514L`.

This PR removes assumptions (1) and (2), broadening the types `std::complex` supports. One example is the type `Eigen::Half` in https://eigen.tuxfamily.org/dox-devel/Half_8h_source.html. This type does not implement implicit conversions.
wangliu-iscas pushed a commit to plctlab/patchwork-gcc that referenced this pull request Mar 27, 2023
Dear all,

Here follows a patch that removes implicit type casts in std::complex.

*Description:* The current implementation of `complex<_Tp>` assumes that
`int, double, long double` are explicitly convertible to `_Tp`. Moreover,
it also assumes that:

1. `int` is implicitly convertible to `_Tp`, e.g., when using
`complex<_Tp>(1)`.
2. `long double` can be attributed to a `_Tp` variable, e.g., when using
`const _Tp __pi_2 = 1.5707963267948966192313216916397514L`.

This patch transforms the implicit casts (1) and (2) into explicit type
casts. As a result, `std::complex` is now able to support more types. One
example is the type `Eigen::Half` from
https://eigen.tuxfamily.org/dox-devel/Half_8h_source.html which does not
implement implicit type conversions.

*ChangeLog:*
libstdc++-v3/ChangeLog:

        * include/std/complex:

*Patch:* fix_complex.diff. (Also at
gcc-mirror/gcc#84)

*OBS:* I didn't find a good reason for adding new tests or test results
here since this is really a small upgrade (in my view) to std::complex.

Sincerely,
  Weslley
@MLopez-Ibanez
Copy link

This is a read-only mirror that is not managed by GCC developers.

Pull requests in this read-only mirror will be ignored forever.

If you wish to contribute to GCC please read: https://gcc.gnu.org/wiki/GettingStarted

@weslleyspereira
Copy link
Author

weslleyspereira commented Oct 13, 2023

Thanks! I sent a contribution as instructed here: https://gcc.gnu.org/wiki/GettingStarted
I will close this PR.

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