Re: [HACKERS] "left shift of negative value" warnings

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [HACKERS] "left shift of negative value" warnings
Дата
Msg-id 324.1491780027@sss.pgh.pa.us
обсуждение исходный текст
Ответ на [HACKERS] "left shift of negative value" warnings  (Andres Freund <andres@anarazel.de>)
Ответы Re: [HACKERS] "left shift of negative value" warnings
Список pgsql-hackers
Andres Freund <andres@anarazel.de> writes:
> For a while I've been getting warnings like
> /home/andres/src/postgresql/src/backend/utils/adt/inet_cidr_ntop.c: In function ‘inet_cidr_ntop_ipv6’:
> /home/andres/src/postgresql/src/backend/utils/adt/inet_cidr_ntop.c:205:11: warning: left shift of negative value
[-Wshift-negative-value]
>     m = ~0 << (8 - b);
>            ^~

I imagine forcing the LHS to unsigned would silence that, though you'd
have to be careful that the sign extension (widening) happened before
you changed the value to unsigned, in the int64 cases.  It's a bit odd
though that it seems to think ~0 is signed.

> If I understand C99 correctly, the behaviour of a left-shift of a
> negative number is undefined (6.5.7 4.).

As I read that, it's only "undefined" if overflow would occur (ie
the sign bit would change).  Your compiler is being a useless annoying
nanny, but that seems to be the in thing for compiler authors these
days.
        regards, tom lane



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Noah Misch
Дата:
Сообщение: Re: [HACKERS] SCRAM authentication, take three
Следующее
От: Tatsuo Ishii
Дата:
Сообщение: Re: [HACKERS] pgbench - allow to store select results intovariables