]> Savannah Git Hosting - gnulib.git/commitdiff
time: Fix compilation errors with clang/MSVC.
authorBruno Haible <bruno@clisp.org>
Wed, 14 Sep 2022 22:50:41 +0000 (00:50 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 18 Sep 2022 19:21:43 +0000 (21:21 +0200)
* 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
lib/time.in.h
m4/time_h.m4

index fb4a2a741db667794129e1e12438b3c85d3d0564..42f0ee99a9071bcfab04aeac9c47256438bddd3e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2022-09-14  Bruno Haible  <bruno@clisp.org>
+
+       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  <bruno@clisp.org>
 
        verify: Avoid syntax error due to static_assert with clang in C++ mode.
index 6d4c7719636f282d4faf8465067950e9c442a6ee..6aa67498f57533d4a38c3af800766cf673ccfc49 100644 (file)
@@ -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
index 98d7b6e01bd74c5a065c94512890e712c8b6bdcb..4ac8fd007525ae11f2f84e4fd806bec4f2ba64d1 100644 (file)
@@ -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 <time.h>
+    ]], [asctime_r ctime_r])
+
   AC_REQUIRE([AC_C_RESTRICT])
 
   AC_CACHE_CHECK([for TIME_UTC in <time.h>],