Skip to content

Conversation

@Conarnar
Copy link

@Conarnar Conarnar commented Aug 8, 2025

Clang 21 adds the warning Wimplicit-int-conversion-on-negation which is when a smaller integer type (char, short) is negated and then converted back to to the smaller type, since negation implicitly converts the value to int.

Adding the casts here should stop the warning.

if ((sign = n < 0)) {
*p++ = '-';
n = -n;
n = (int8_t)-n;
Copy link
Collaborator

@bjosv bjosv Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative seems to be n *= -1; which also silences the warning..but I don't know if that is a glitch in clang.
Feels like that also would be an implicit conversion due to integer promotion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants