This question Implicit type conversion rules in C++ operators (and several others) state
If either is long long unsigned int the other is promoted to long long unsigned int
However if I do the following under MSVC:
unsigned int a = <some expression>;
unsigned long long b = a << 32ULL;
The second line generates the following warning:
warning C4293: '<<': shift count negative or too big, undefined behavior
32ULL
is a 64 bit unsigned value, therefore according to the implicit conversion rules this should mean that a
is converted to unsigned long long
as well. Hence I'm shifting a 64 bit value by 32 bits, clearly a well defined operation.
Is MSVC bugged or is there a flaw in my logic?
An implicit conversion sequence is the sequence of conversions required to convert an argument in a function call to the type of the corresponding parameter in a function declaration. The compiler tries to determine an implicit conversion sequence for each argument.
Implicit conversions: No special syntax is required because the conversion always succeeds and no data will be lost. Examples include conversions from smaller to larger integral types, and conversions from derived classes to base classes.
Implicit conversions allow the compiler to treat values of a type as values of another type. There's at least one set of scenarios in which this is unambiguously bad: non-total conversions. That is, converting an A to a B when there exists A s for which this conversion is impossible.
Implicit conversions are not visible to the user. SQL Server automatically converts the data from one data type to another. For example, when a smallint is compared to an int, the smallint is implicitly converted to int before the comparison proceeds.
Shifts don't do the so-called "usual arithmetic conversions", which is the rules you cited. They only perform integral promotions. The result of a shift is of the same type as the promoted left operand.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With