From owner-freebsd-hackers@FreeBSD.ORG Tue Mar 12 03:17:10 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id A1F626F4; Tue, 12 Mar 2013 03:17:10 +0000 (UTC) (envelope-from adrian.chadd@gmail.com) Received: from mail-wi0-x22f.google.com (mail-wi0-x22f.google.com [IPv6:2a00:1450:400c:c05::22f]) by mx1.freebsd.org (Postfix) with ESMTP id 1F3FE327; Tue, 12 Mar 2013 03:17:09 +0000 (UTC) Received: by mail-wi0-f175.google.com with SMTP id l13so1468505wie.8 for ; Mon, 11 Mar 2013 20:17:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:sender:date:x-google-sender-auth:message-id :subject:from:to:cc:content-type; bh=E3s/U9vOwscCZU2LPAZqm/01ydGxLYfJw5yPfEWZKz8=; b=MjT2g0NLgS+Muqj1tbBly1ayB5inreSx5Qx1uTVe0MX2KYstGG0BzaiEcBYJPbPp36 1sv9hSfh5RSeZ9s7Q8RssuREUQwQmO/yAOBiptY2PqbeI8cIXlGtcbeKzsNY25MaQAL5 0IOQdvNmtgYR1sqAnD8tuFgahE1w/Jgib9Y9cf1V2QSBn+OiqM6TxViA56NV8Vq2mM2S 52JTCS0OggZVLxgUMd7mXLD16CUlO1/LWrhqIMJk+sKqivQPkUZtn33cMi4Ln1qiPFCy 8VZV1im+Jm+GXvWF/YOGVfbARpk0BA4FUObRKZ9a7FVM6I2793awsHL4tlWujkBmG8wi Wk/g== MIME-Version: 1.0 X-Received: by 10.180.94.135 with SMTP id dc7mr16637127wib.11.1363058228902; Mon, 11 Mar 2013 20:17:08 -0700 (PDT) Sender: adrian.chadd@gmail.com Received: by 10.216.111.201 with HTTP; Mon, 11 Mar 2013 20:17:08 -0700 (PDT) Date: Mon, 11 Mar 2013 20:17:08 -0700 X-Google-Sender-Auth: 0sz8j-v-WWrN-p7XD8qvcXe8xws Message-ID: Subject: clang - odd macro / conditional expansion behaviour? From: Adrian Chadd To: Dimitry Andric Content-Type: text/plain; charset=ISO-8859-1 Cc: freebsd-hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Mar 2013 03:17:10 -0000 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