Messages in this thread | | | From | Linus Torvalds <> | Date | Sun, 27 Nov 2022 12:36:33 -0800 | Subject | Re: [PATCH 1/1] minmax.h: Slightly relax the type checking done by min() and max(). |
| |
On Fri, Nov 25, 2022 at 7:00 AM David Laight <David.Laight@aculab.com> wrote: > > - Skip the type test if either argument is a positive 'int' constant. > Instead cast the constant to 'int', the compiler may promote it > back to 'unsigned int' when doing the test.
No. This looks very wrong to me.
Maybe I'm mis-reading something, but it looks like this makes a "sizeof()" essentially be compatible with an "int" variable.
That is horrendously wrong. It should warn.
If you are doing a "min(i,sizeof(X))", and "i" is a signed integer, then something is wrong. What does that code expect? It shouldn't silently say "this is ok", because it most definitely isn't.
So maybe I'm mis-reading this all and it doesn't actually do what I think it does, but this seems to relax things *much* too much.
There's a reason we require types to be compatible, and you just removed some of the important signedness checks.
Linus
| |