linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] typecheck.h: Force a compilation error if typecheck(type,x) fails
@ 2022-02-03 14:35 Ian Abbott
  2022-06-24 10:56 ` [RESEND PATCH] " Ian Abbott
  0 siblings, 1 reply; 2+ messages in thread
From: Ian Abbott @ 2022-02-03 14:35 UTC (permalink / raw)
  To: linux-kernel; +Cc: Ian Abbott

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.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [RESEND PATCH] typecheck.h: Force a compilation error if typecheck(type,x) fails
  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
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Abbott @ 2022-06-24 10:56 UTC (permalink / raw)
  To: linux-kernel; +Cc: Ian Abbott

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-24 10:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-03 14:35 [PATCH] typecheck.h: Force a compilation error if typecheck(type,x) fails Ian Abbott
2022-06-24 10:56 ` [RESEND PATCH] " Ian Abbott

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).