RE: [PATCH next v2 02/11] minmax: Use _Static_assert() instead of static_assert()

From
Jani Nikula <jani.nikula@linux.intel.com>
Date
2024-02-26 10:27:29
Also in
dri-devel, linux-btrfs, lkml
Reply to
David Laight, 2024-02-26
On Mon, 26 Feb 2024, David Laight [off-list ref] wrote:
From: Jani Nikula
quoted
Sent: 26 February 2024 09:28

On Sun, 25 Feb 2024, David Laight [off-list ref] wrote:
quoted
The wrapper just adds two more lines of error output when the test fails.
There are only a handful of places in kernel code that use
_Static_assert() directly. Nearly 900 instances of static_assert().
How many of those supply an error message?
At a glance, not many.
quoted
Are we now saying it's fine to use _Static_assert() directly all over
the place? People will copy-paste and cargo cult.
Is that actually a problem?
I don't know. I'm asking.

Usually when we have compiler wrappers, they're meant to be used instead
of the thing being wrapped.

This series deviates from that, so it would seem to fair to mention it
slightly more verbosely than just stating what's being done.
The wrapper allows the error message to be omitted and substitutes
the text of the conditional.
But it isn't 'free'.
As well as slightly slowing down the compilation, the error messages
from the compiler get more difficult to interpret.

Most of the static_assert() will probably never generate an error.
But the ones in min()/max() will so it is best to make them as
readable as possible.
(Don't even look as the mess clang makes....)
I'm not arguing any of this. :)


BR,
Jani.


-- 
Jani Nikula, Intel
Thread (24 messages) 24 messages, 5 authors, last reply 2024-02-27
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help