public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib: typecheck: initialize const variable to avoid Clang warning
@ 2026-03-15  8:52 hamjin
  2026-03-15 15:12 ` kernel test robot
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: hamjin @ 2026-03-15  8:52 UTC (permalink / raw)
  To: linux-kernel; +Cc: hamjin

Building the kernel with newer Clang versions triggers
-Wdefault-const-init-var-unsafe in the typecheck() macro:

  error: default initialization of an object of type 'const unsigned long'
  leaves the object uninitialized [-Wdefault-const-init-var-unsafe]

The warning originates from the following declaration in typecheck():

    typeof(x) __dummy2;

When 'x' has a const-qualified type (e.g. 'const unsigned long'),
Clang warns that the variable is declared const but not initialized.
With -Werror enabled this causes the build to fail.

Initialize the temporary variable to zero to silence the warning:

    typeof(x) __dummy2 = (typeof(x))0;

This variable is only used for compile-time type checking and its
value is never read, so the initialization has no functional impact
on the generated code.

Fixes: e0deaff47090 ("split the typecheck macros out of include/linux/kernel.h")
Signed-off-by: hamjin <jinham@qq.com>
---
 include/linux/typecheck.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/typecheck.h b/include/linux/typecheck.h
index 46b15e2aaefb..09f280da5b52 100644
--- a/include/linux/typecheck.h
+++ b/include/linux/typecheck.h
@@ -8,7 +8,7 @@
  */
 #define typecheck(type,x) \
 ({	type __dummy; \
-	typeof(x) __dummy2; \
+	typeof(x) __dummy2 = (typeof(x))0; \
 	(void)(&__dummy == &__dummy2); \
 	1; \
 })
-- 
2.53.0


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

end of thread, other threads:[~2026-03-26  2:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-15  8:52 [PATCH] lib: typecheck: initialize const variable to avoid Clang warning hamjin
2026-03-15 15:12 ` kernel test robot
2026-03-25 12:07 ` kernel test robot
2026-03-25 12:52 ` kernel test robot
2026-03-26  2:04 ` Nathan Chancellor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox