From 0152675d8e6371279395606958a58b9d716c591e Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 15 Sep 2022 00:50:41 +0200 Subject: [PATCH] time: Fix compilation errors with clang/MSVC. * m4/time_h.m4 (gl_TIME_H): Test whether asctime_r and ctime_r are declared. * lib/time.in.h (asctime_r, ctime_r): Skip _GL_WARN_ON_USE invocations when these functions are not declared. --- ChangeLog | 8 ++++++++ lib/time.in.h | 4 ++++ m4/time_h.m4 | 8 +++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index fb4a2a741d..42f0ee99a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2022-09-14 Bruno Haible + + time: Fix compilation errors with clang/MSVC. + * m4/time_h.m4 (gl_TIME_H): Test whether asctime_r and ctime_r are + declared. + * lib/time.in.h (asctime_r, ctime_r): Skip _GL_WARN_ON_USE invocations + when these functions are not declared. + 2022-09-14 Bruno Haible verify: Avoid syntax error due to static_assert with clang in C++ mode. diff --git a/lib/time.in.h b/lib/time.in.h index 6d4c771963..6aa67498f5 100644 --- a/lib/time.in.h +++ b/lib/time.in.h @@ -435,8 +435,10 @@ _GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - " # endif # if defined GNULIB_POSIXCHECK # undef asctime_r +# if HAVE_RAW_DECL_ASCTIME_R _GL_WARN_ON_USE (asctime_r, "asctime_r can overrun buffers in some cases - " "better use strftime (or even sprintf) instead"); +# endif # endif # if defined GNULIB_POSIXCHECK # undef ctime @@ -445,8 +447,10 @@ _GL_WARN_ON_USE (ctime, "ctime can overrun buffers in some cases - " # endif # if defined GNULIB_POSIXCHECK # undef ctime_r +# if HAVE_RAW_DECL_CTIME_R _GL_WARN_ON_USE (ctime_r, "ctime_r can overrun buffers in some cases - " "better use strftime (or even sprintf) instead"); +# endif # endif #endif diff --git a/m4/time_h.m4 b/m4/time_h.m4 index 98d7b6e01b..4ac8fd0075 100644 --- a/m4/time_h.m4 +++ b/m4/time_h.m4 @@ -2,7 +2,7 @@ # Copyright (C) 2000-2001, 2003-2007, 2009-2022 Free Software Foundation, Inc. -# serial 19 +# serial 20 # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -19,6 +19,12 @@ AC_DEFUN_ONCE([gl_TIME_H], gl_NEXT_HEADERS([time.h]) AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC]) + dnl Check for declarations of anything we want to poison if the + dnl corresponding gnulib module is not in use. + gl_WARN_ON_USE_PREPARE([[ +#include + ]], [asctime_r ctime_r]) + AC_REQUIRE([AC_C_RESTRICT]) AC_CACHE_CHECK([for TIME_UTC in ], -- 2.39.5