Skip to content

Fix: int variable casted with as to size_t does not fail on compile time - closes #1257 #1258

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

Closed

Conversation

filipsajdak
Copy link
Contributor

The current implementation of is_narrowing_v does not handle type conversions correctly. For example, cpp2::impl::is_narrowing_v<std::size_t, int> returns false, indicating that it mistakenly perceives the conversion from a signed int to an unsigned size_t as potentially non-narrowing.

The new implementation is based on curly braces initialization on the cpp1 side which does all the required checking correctly. Examples here: https://godbolt.org/z/EdEK75E7z

Closes #1257

@filipsajdak filipsajdak force-pushed the fsajdak-fix-is-narrowing branch from 83563ac to 2642c2b Compare August 23, 2024 21:46
The current implementation of `is_narrowing_v` does not handle type conversions correctly.
For example, `cpp2::impl::is_narrowing_v<std::size_t, int>` returns `false`,
indicating that it mistakenly perceives the conversion from a signed `int` to an unsigned `size_t`
as potentially non-narrowing.

Closes hsutter#1257
@filipsajdak filipsajdak force-pushed the fsajdak-fix-is-narrowing branch from 2642c2b to 426dd8e Compare August 27, 2024 20:15
@hsutter
Copy link
Owner

hsutter commented Sep 24, 2024

Thanks! Looks good except for the conflicts -- can you take a pass through to resolve those? Then this should be ready to merge, thanks again.

@gregmarr
Copy link
Contributor

gregmarr commented Oct 4, 2024

@hsutter Have you reviewed the discussion in #1257 about whether this change is actually wanted, or if other things should be updated to the current behavior here?

@hsutter
Copy link
Owner

hsutter commented Oct 5, 2024

@gregmarr No, thanks for the reminder!

@hsutter
Copy link
Owner

hsutter commented Mar 1, 2025

Re #1257: Thanks for the discussion! I'm going to stick with status quo on this for now, but please feel free to reopen if over time you find this keeps causing problems or user surprise.

@hsutter hsutter closed this Mar 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] int variable casted with as to size_t does not fail on compile time
4 participants