From e8994dfe170b979d5298abed658cc1a71a2d0417 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 6 Nov 2025 09:07:25 +1000 Subject: [PATCH] util: add handling for an auto type Because sometimes it's much easier and more readable, e.g. auto eis_device = eis_touchscreen_get_device(...) Part-of: --- meson.build | 9 +++++++++ src/util-macros.h | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/meson.build b/meson.build index 4ab047f..cccab65 100644 --- a/meson.build +++ b/meson.build @@ -74,6 +74,15 @@ if cc.has_function('memfd_create', prefix: '#define _GNU_SOURCE\n#include + +void func() { auto foo = gmtime(NULL); foo->tm_sec = 0; } +''' +if cc.compiles(code, name: 'has C23 auto keyword') + config_h.set('HAVE_C23_AUTO', '1') +endif + dep_math = cc.find_library('m', required: false) dep_epoll = dependency('epoll-shim', required: false) dep_libxkbcommon = dependency('xkbcommon', required: false) diff --git a/src/util-macros.h b/src/util-macros.h index f3ee5b1..369ca58 100644 --- a/src/util-macros.h +++ b/src/util-macros.h @@ -31,6 +31,10 @@ #include #include +#ifndef HAVE_C23_AUTO +#define auto __auto_type +#endif + #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) #define ARRAY_FOR_EACH(_arr, _elem) \ for (size_t _i = 0; _i < ARRAY_LENGTH(_arr) && (_elem = &_arr[_i]); _i++)