I would prefer that the definition of narrowing be defined on the types themselves. So that int i{long(non_constant_expression)} never allowed to compile. A simple reason: either you do not need a large range, then you must use int first and foremost, or you really want to โcutโ, which seems to be a rather rare case for me to require an explicit type of transform or cast. To answer the first question: Implementation is defined.
But honestly, I almost never use these raw types, just size_t , int32_t , uint16_t , etc., and this automatically solves the problem. ( uint16_t {uint8_t()} always narrows, uint16_t{uint16_t()} never.) You just need to thoughtfully convert size_t to something else, but that's always the case.
source share