From owner-freebsd-toolchain@FreeBSD.ORG Sun Nov 6 20:52:33 2011 Return-Path: Delivered-To: freebsd-toolchain@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E3CBA106564A; Sun, 6 Nov 2011 20:52:33 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from tensor.andric.com (cl-327.ede-01.nl.sixxs.net [IPv6:2001:7b8:2ff:146::2]) by mx1.freebsd.org (Postfix) with ESMTP id A67D28FC0C; Sun, 6 Nov 2011 20:52:33 +0000 (UTC) Received: from [IPv6:2001:7b8:3a7:0:a81b:6656:1bbc:a3f7] (unknown [IPv6:2001:7b8:3a7:0:a81b:6656:1bbc:a3f7]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by tensor.andric.com (Postfix) with ESMTPSA id D9BB45C59; Sun, 6 Nov 2011 21:52:32 +0100 (CET) Message-ID: <4EB6F38E.2080006@FreeBSD.org> Date: Sun, 06 Nov 2011 21:52:30 +0100 From: Dimitry Andric Organization: The FreeBSD Project User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111031 Thunderbird/8.0 MIME-Version: 1.0 To: Alexander Best References: <20111105102102.GA54596@freebsd.org> <20111106172835.GO2258@hoeg.nl> <20111106203316.GA73216@freebsd.org> In-Reply-To: <20111106203316.GA73216@freebsd.org> X-Enigmail-Version: 1.3.3 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: freebsd-toolchain@freebsd.org Subject: Re: [poc] buildkernel + clang + -Werror X-BeenThere: freebsd-toolchain@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Maintenance of FreeBSD's integrated toolchain List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Nov 2011 20:52:34 -0000 On 2011-11-06 21:33, Alexander Best wrote: ... > the problem is, something like > > uint x; > > if (x < 0) ... > > clang will warn about this, yet it is 100% valid code so my vote would be to > make such an error into a warning. Sorry, but checking something unsigned to be smaller than zero is bogus, or at the least superfluous, and it's perfectly sane to warn about this, especially since the compiler is not going to emit code for it at all. The only time when this sort of check could be relevant, is when you are using a typedef'd type, and you have no way to be sure if the type is signed or unsigned. But then you will be in for trouble anyway... ... > the same with > > int x; > > x = x; > > i believe in both cases clang is too picky. This is a often-used idiom for attempting to 'shut up' a compiler when it (quite legitimately) complains about unused variables or arguments. However, a better idiom is: (void) x; but even this can lead some compilers or analysis tools to complain about "statements that don't do anything". A better way is to provide UNUSED_VARIABLE and UNUSED_ARGUMENT macros, and handle shutting up the compiler in its specific way there. Of course, the best solution is to just eliminate the unused variables or arguments. If that is not possible, for example due to a function signature that cannot be changed because of API considerations, you can always use __unused attributes.