From ecd4ea305312e150ec326db27046351caa6473aa Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 7 Apr 2025 07:35:25 +1000 Subject: [PATCH] util: add a wrapper for the C23 auto keyword C23 auto is basically __auto_type so let's wrap it if our compiler doesn't provide it (yet). This lets us use `auto` as type specifier, e.g. compare enum libinput_config_status status = libinput_device_config_set(...) auto status = libinput_device_config_set(...) Note that as of now meson will never detect this as it requires -std=c23 to be passed to the compiler. This flag is only supported by Clang 18 (released 2024) and we don't want to break things for older compilers for what is a bit of a niche feature right now. Part-of: --- meson.build | 7 +++++++ src/util-macros.h | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/meson.build b/meson.build index 0c7d6300..68fb91ee 100644 --- a/meson.build +++ b/meson.build @@ -133,6 +133,13 @@ if cc.has_header('xlocale.h') config_h.set('HAVE_XLOCALE_H', '1') endif +code = ''' +void func() { auto foo = "test"; } +''' +if cc.compiles(code, name: 'has C23 auto keyword') + config_h.set('HAVE_C23_AUTO', '1') +endif + code = ''' #include void main(void) { newlocale(LC_NUMERIC_MASK, "C", (locale_t)0); } diff --git a/src/util-macros.h b/src/util-macros.h index 29a34f6a..4fb78dc3 100644 --- a/src/util-macros.h +++ b/src/util-macros.h @@ -27,6 +27,10 @@ #include "config.h" +#ifndef HAVE_C23_AUTO +#define auto __auto_type +#endif + #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) /** * Iterate through the array _arr, assigning the variable elem to each