[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <c6f0c3d8-eb2b-49e1-b874-610fbeb248e4@p183>
Date: Sat, 27 Dec 2025 17:51:49 +0300
From: Alexey Dobriyan <adobriyan@...il.com>
To: David Laight <david.laight.linux@...il.com>
Cc: corbet@....net, workflows@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 6/9] CodingStyle: recommend static_assert/_Static_assert
On Tue, May 13, 2025 at 08:40:31PM +0100, David Laight wrote:
> On Fri, 9 May 2025 23:34:27 +0300
> Alexey Dobriyan <adobriyan@...il.com> wrote:
>
> > Linux's BUG_ON is done backwards (condition is inverted).
> > But it is a long story.
> >
> > However C11/C23 allow to partially transition to what all normal
> > programmers are used to, namely assert().
> >
> > Deprecate BUILD_BUG_ON, recommend static_assert/_Static_assert.
> > And then some day BUG_ON will be flipped as well.
>
> _Static_assert() is broken by design and only usable for trival tests.
It is not broken by design. I was going to recommend it
for "static_assert(sizeof(struct S) == ...)" type of things. For ABI types and
similar stuff.
BTW BUILD_BUG_ON is broken by design too, there are places with fake functions
for a block so that they can put statement in.
> clang also output the entire expansion of the conditional (even when
> a message is specified) which can lead to very very very very long lines.
Oh, that's very unfortunate.
> It isn't at all suitable for many of the checks in the kernel.
STATIC_ASSERT could be arranged.
> Look at the signedness test in min() as an example.
The very fact you all made giant mess trying to imitate min<T, U>()
should not block progress of using standard (and better!) stuff.
Powered by blists - more mailing lists