cppfront icon indicating copy to clipboard operation
cppfront copied to clipboard

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

Open filipsajdak opened this issue 1 year ago • 3 comments
trafficstars

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 avatar Aug 23 '24 20:08 filipsajdak

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.

hsutter avatar Sep 24 '24 04:09 hsutter

@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?

gregmarr avatar Oct 04 '24 21:10 gregmarr

@gregmarr No, thanks for the reminder!

hsutter avatar Oct 05 '24 03:10 hsutter

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 avatar Mar 01 '25 18:03 hsutter