All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ian Abbott <abbotti@mev.co.uk>
To: linux-kernel@vger.kernel.org
Cc: Ian Abbott <abbotti@mev.co.uk>
Subject: [RESEND PATCH] typecheck.h: Force a compilation error if typecheck(type,x) fails
Date: Fri, 24 Jun 2022 11:56:12 +0100	[thread overview]
Message-ID: <20220624105612.137575-1-abbotti@mev.co.uk> (raw)
In-Reply-To: <20220203143557.218112-1-abbotti@mev.co.uk>

Calling the `typecheck(type,x)` macro emits a compiler warning if the
type of `x` is incompatible with type `type`.  Change it to force a
compilation error instead.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
 include/linux/typecheck.h | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/include/linux/typecheck.h b/include/linux/typecheck.h
index 46b15e2aaefb..c9125304f6ba 100644
--- a/include/linux/typecheck.h
+++ b/include/linux/typecheck.h
@@ -2,14 +2,15 @@
 #ifndef TYPECHECK_H_INCLUDED
 #define TYPECHECK_H_INCLUDED
 
+#include <linux/compiler_types.h>
+#include <linux/build_bug.h>
+
 /*
  * Check at compile time that something is of a particular type.
  * Always evaluates to 1 so you may use it easily in comparisons.
  */
 #define typecheck(type,x) \
-({	type __dummy; \
-	typeof(x) __dummy2; \
-	(void)(&__dummy == &__dummy2); \
+({	BUILD_BUG_ON(!__same_type(type, (x))); \
 	1; \
 })
 
-- 
2.35.1


      reply	other threads:[~2022-06-24 10:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-03 14:35 [PATCH] typecheck.h: Force a compilation error if typecheck(type,x) fails Ian Abbott
2022-06-24 10:56 ` Ian Abbott [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220624105612.137575-1-abbotti@mev.co.uk \
    --to=abbotti@mev.co.uk \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.