public inbox for linux-kernel-mentees@lists.linux-foundation.org
 help / color / mirror / Atom feed
From: "Hanne-Lotta Mäenpää" <hannelotta@gmail.com>
To: akpm@linux-foundation.org
Cc: kees@kernel.org, gustavoars@kernel.org,
	skhan@linuxfoundation.org, david.hunter.linux@gmail.com,
	linux-kernel@vger.kernel.org,
	linux-kernel-mentees@lists.linux.dev,
	"Hanne-Lotta Mäenpää" <hannelotta@gmail.com>
Subject: [PATCH] headers: Add check for C standard version
Date: Sun, 26 Oct 2025 21:58:46 +0200	[thread overview]
Message-ID: <20251026195846.69740-1-hannelotta@gmail.com> (raw)

Compiling the kernel with GCC 15 results in errors, as with GCC 15
the default language version for C compilation has been changed from
-std=gnu17 to -std=gnu23 - unless the language version has been
changed using

    KBUILD_CFLAGS += -std=gnu17

or earlier.

C23 includes new keywords 'bool', 'true' and 'false', which cause
compilation errors in Linux headers:

    ./include/linux/types.h:30:33: error: ‘bool’ cannot be defined
        via ‘typedef’

    ./include/linux/stddef.h:11:9: error: cannot use keyword ‘false’
        as enumeration constant

Add check for C Standard's version in the header files to be able
to compile the kernel with C23.

Signed-off-by: Hanne-Lotta Mäenpää <hannelotta@gmail.com>
---
 include/linux/stddef.h | 2 ++
 include/linux/types.h  | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/include/linux/stddef.h b/include/linux/stddef.h
index 80b6bfb944f0..aa2cb3db3c06 100644
--- a/include/linux/stddef.h
+++ b/include/linux/stddef.h
@@ -7,10 +7,12 @@
 #undef NULL
 #define NULL ((void *)0)
 
+#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 202311L
 enum {
 	false	= 0,
 	true	= 1
 };
+#endif
 
 #undef offsetof
 #define offsetof(TYPE, MEMBER)	__builtin_offsetof(TYPE, MEMBER)
diff --git a/include/linux/types.h b/include/linux/types.h
index 6dfdb8e8e4c3..931db48a7a09 100644
--- a/include/linux/types.h
+++ b/include/linux/types.h
@@ -32,7 +32,9 @@ typedef __kernel_timer_t	timer_t;
 typedef __kernel_clockid_t	clockid_t;
 typedef __kernel_mqd_t		mqd_t;
 
+#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 202311L
 typedef _Bool			bool;
+#endif
 
 typedef __kernel_uid32_t	uid_t;
 typedef __kernel_gid32_t	gid_t;
-- 
2.51.0


                 reply	other threads:[~2025-10-26 19:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20251026195846.69740-1-hannelotta@gmail.com \
    --to=hannelotta@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=david.hunter.linux@gmail.com \
    --cc=gustavoars@kernel.org \
    --cc=kees@kernel.org \
    --cc=linux-kernel-mentees@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=skhan@linuxfoundation.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