Date: Mon, 11 Mar 2013 20:17:08 -0700 From: Adrian Chadd <adrian@freebsd.org> To: Dimitry Andric <dim@freebsd.org> Cc: freebsd-hackers@freebsd.org Subject: clang - odd macro / conditional expansion behaviour? Message-ID: <CAJ-Vmonn1m_AMiJbxfGDM%2BXrpfF%2BLKunSeoUWgkF9QVaMKf5ew@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
I've hit this rather amusing clang behaviour:
In file included from
/usr/home/adrian/work/freebsd/ath/head/src/sys/modules/ath/../../contrib/sys/dev/ath/ath_hal/ar9300/ar9300_eeprom.c:21:
/usr/home/adrian/work/freebsd/ath/head/src/sys/modules/ath/../../contrib/sys/dev/ath/ath_hal/ar9300/ar9300template_generic.h:107:3:
error: implicit conversion from 'int' to
'u_int8_t' (aka 'unsigned char') changes value from -477 to 35
[-Werror,-Wconstant-conversion]
FREQ2FBIN(2412, 1),
^~~~~~~~~~~~~~~~~~
/usr/home/adrian/work/freebsd/ath/head/src/sys/modules/ath/../../contrib/sys/dev/ath/ath_hal/ar9300/ar9300eep.h:136:65:
note: expanded from macro 'FREQ2FBIN'
(((y) == HAL_FREQ_BAND_2GHZ) ? ((x) - 2300) : (((x) - 4800) / 5))
~~~~~~~~~~~~~^~~
.. now, HAL_FREQ_BAND_2GHZ is defined here as:
typedef enum {
HAL_FREQ_BAND_5GHZ = 0,
HAL_FREQ_BAND_2GHZ = 1,
} HAL_FREQ_BAND;
And:
#define FREQ2FBIN(x,y) \
(((y) == HAL_FREQ_BAND_2GHZ) ? ((x) - 2300) : (((x) - 4800) / 5))
And all of those macros here have '1' in the second field, yet when
they're expanded they evaluate as if it were false.
So, what's going on? :-) gcc is fine with this. :)
Thanks!
Adrian
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAJ-Vmonn1m_AMiJbxfGDM%2BXrpfF%2BLKunSeoUWgkF9QVaMKf5ew>
