Does C++ allow any integer literal to be implicitly converted to a short int?

Yes, integers can be converted implicitly. These are the rules from the C++ standard draft N4296:

4.7 Integral conversions
1 A prvalue of an integer type can be converted to a prvalue of another integer type. A prvalue of an unscoped enumeration type can be converted to a prvalue of an integer type.
2 If the destination type is unsigned, the resulting value is the least unsigned integer congruent to the source integer (modulo 2n where n is the number of bits used to represent the unsigned type).
[ Note: In a two’s complement representation, this conversion is conceptual and there is no change in the bit pattern (if there is no truncation). —end note ]
3 If the destination type is signed, the value is unchanged if it can be represented in the destination type; otherwise, the value is implementation-defined.
4 If the destination type is bool, see 4.12. If the source type is bool, the value false is converted to zero and the value true is converted to one.
5 The conversions allowed as integral promotions are excluded from the set of integral conversions.


The standard allows the implicit conversion between any two integer types, regardless of their values.

The compiler warnings are unrelated to the code being legal; the compiler just warns you when your code probably does not do what you wanted it to.

In your specific case, n1 would be 8 and n2 would have an implementation defined value. Both assignments are legal C++, but the latter is probably not what you intended.


Relevant standardese:

A prvalue of an integer type can be converted to a prvalue of another integer type. A prvalue of an unscoped enumeration type can be converted to a prvalue of an integer type.
If the destination type is unsigned, the resulting value is the least unsigned integer congruent to the source integer (modulo 2n where n is the number of bits used to represent the unsigned type). [ Note: In a two’s complement representation, this conversion is conceptual and there is no change in the bit pattern (if there is no truncation). — end note ]
If the destination type is signed, the value is unchanged if it can be represented in the destination type (and bit-field width); otherwise, the value is implementation-defined.

4.7/1-3 in N4141