The actual issue here is that use of unary minus operator, just like the rest of built-in arithmetic operators, is a subject to integral promotions. So surprisingly the result of applying unary minus to size_t
will be still size_t
and there is no need to blame auto
.
Counter-example. In this case due to integral promotions type of x
will be int
so output will be -1
:
unsigned short a{1};
auto x{-a};
cout << x << endl;