From: hamjin <jinham@qq.com>
To: linux-kernel@vger.kernel.org
Cc: hamjin <jinham@qq.com>
Subject: [PATCH] lib: typecheck: initialize const variable to avoid Clang warning
Date: Sun, 15 Mar 2026 16:52:48 +0800 [thread overview]
Message-ID: <tencent_274FD06231C70768C2C28FD13673A24C2B08@qq.com> (raw)
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
next reply other threads:[~2026-03-15 8:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-15 8:52 hamjin [this message]
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
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=tencent_274FD06231C70768C2C28FD13673A24C2B08@qq.com \
--to=jinham@qq.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®