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

Non-optimal code generation for narrow<long long int>(char) #926

Open
HFriberg opened this issue Sep 8, 2020 · 0 comments
Open

Non-optimal code generation for narrow<long long int>(char) #926

HFriberg opened this issue Sep 8, 2020 · 0 comments

Comments

@HFriberg
Copy link

HFriberg commented Sep 8, 2020

A quick test on Godbolt showed that the latest ICC compiler (v19.0.1) does not recognize that char can always be converted to long long int without loss of precision with the current implementation of narrow:
https://godbolt.org/z/73zPhG

I suggest wrapping the current implementation of narrow in a compile-time check on types, to see if there is any reason to check the values. Ideas:

  1. One suggestion from stackoverflow I haven't tested is this:
if constexpr( !std::is_same<T, typename std::common_type<T,U>::type>::value )
  1. Another suggestion is to use the is_narrowing_conversion definition from https://riccibruno.github.io/2018/04/27/c++_is_narrowing_conversion_type_trait/.
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

No branches or pull requests

1 participant