[PATCH] lib: typecheck: initialize const variable to avoid Clang warning
From: hamjin
Date: Sun Mar 15 2026 - 04:53:46 EST
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@xxxxxx>
---
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