meson.build: fix detection of C23 auto

Sadly, this detection was broken because in C everything defaults to
type int. Casting a const char* to int is permitted but generates a
warning which was promptly ignored by meson.

This result in HAVE_C23_AUTO being set on compilers that don't by
default have -Werror=implicit-int and "auto" ended up being just an
"int".

Change the detection to use gmtime() which returns a struct, and add a
basic test using one of our struct-returning utility functions, just to
be sure.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1198>
This commit is contained in:
Peter Hutterer 2025-05-08 19:37:54 +10:00 committed by Marge Bot
parent 04975b4618
commit 8177a685c2
2 changed files with 13 additions and 1 deletions

View file

@ -134,7 +134,9 @@ if cc.has_header('xlocale.h')
endif
code = '''
void func() { auto foo = "test"; }
#include <time.h>
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')

View file

@ -51,6 +51,15 @@
#define TEST_VERSIONSORT
#include "libinput-versionsort.h"
START_TEST(auto_test)
{
/* This one is just a compile test */
auto tv = us2tv(0);
tv.tv_sec = 0;
litest_assert_int_eq(tv.tv_sec, 0);
}
END_TEST
START_TEST(mkdir_p_test)
{
const char *testdir = "/tmp/litest_mkdir_test";
@ -2258,6 +2267,7 @@ int main(void)
litest_runner_add_test(runner, &tdesc); \
} while(0)
ADD_TEST(auto_test);
ADD_TEST(mkdir_p_test);
ADD_TEST(array_for_each);