cppfront
cppfront copied to clipboard
Fix: `int` variable casted with as to `size_t` does not fail on compile time - closes #1257
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
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 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 No, thanks for the reminder!
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.