I'm currently dealing with some MISRA issues and therefore trying to understand the integer conversion rules in C.
I'm getting a violation of MISRA-C 2004 rule 12.9 The unary minus operator shall not be applied to an expression whose underlying type is unsigned
in the code line
signed long int test = -1;
I understand that there is no negative integer constant "-1", but rather the unary minus applied to the integer constant "1" (as stated in https://en.cppreference.com/w/c/language/integer_constant).
The integer constant "1" however is of the first type in the list int, long int, unsigned long int (until C99), long long int (since C99)
I'm compling with Keil (ARM 32 bits) and the --c99 flag set, while MISRA-C 2004 seems to be based on the C90 standard.
So it seems as my SCA tool is assuming the "1" constant is of type unsigned long int (until C99), but I can't see, why it wouldn't fit in an ordinary int and therefore be signed.
To satisfy the SCA tool, one has to code
signed long int test = -1L;
or
signed long int test = -((signed long int) 1);
Is this correct behaviour or am I missing something here?