Due to integer promotion, on platforms on which int is 32 bits, the expression
~(DefaultValueForPortStatus)
evaluates to an int with the value -65536.
What exactly happens is the following:
Before the bitwise-NOT (~) operation takes place, the operand DefaultValueForPortStatus gets promoted to an int, so that its memory representation will be equivalent to that of an unsigned int with the following value:
0x0000FFFF
After applying the bitwise-NOT (~) operator to it, its memory representation will be equivalent to that of an unsigned int with the following value:
0xFFFF0000
However, the result has the data type int, not unsigned int. (I am only using the equivalent values of unsigned int for illustrating the memory representation.) Therefore, the actual value of the result is -65536 (because C++ requires that two's complement memory representation is used for signed integers).
When converting this int to uint16_t to match the type of the function parameter, the 16 most significant bits are discarded and the 16 least significant bits are preserved. Therefore, the function argument will have the value 0.
When compiling using default settings, gcc provides a warning of such truncations, if they occur in a constant expression. This warning can be disabled with the -Wno-overflow command line option.
The reason why the compiler warns by default is probably because it assumes that such truncations are not intended to occur in constant expressions. It does not make this assumption with expressions that are based on non-const variables.
The truncation will occur either way, whether the compiler issues a warning or not.