[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
time: Fix compilation errors with clang/MSVC
From: |
Bruno Haible |
Subject: |
time: Fix compilation errors with clang/MSVC |
Date: |
Thu, 15 Sep 2022 01:07:35 +0200 |
Building a gnulib testdir on Windows, with clang and the MSVC header files, I
get these compilation errors:
In file included from C:\cygwin64\home\bruno\testdir-all\gllib\accept.c:27:
In file included from ../../gllib/w32sock.h:23:
In file included from .\fcntl.h:64:
In file included from .\sys/stat.h:44:
.\time.h(945,18): error: use of undeclared identifier 'asctime_r'; did you mean
'asctime_s'?
_GL_WARN_ON_USE (asctime_r, "asctime_r can overrun buffers in some cases - "
^~~~~~~~~
asctime_s
.\sys/socket.h(529,31): note: expanded from macro '_GL_WARN_ON_USE'
_GL_WARN_EXTERN_C __typeof__ (function) function \
^
In file included from C:\cygwin64\home\bruno\testdir-all\gllib\accept.c:27:
In file included from ../../gllib/w32sock.h:23:
In file included from .\fcntl.h:64:
In file included from .\sys/stat.h:44:
.\time.h(955,18): error: use of undeclared identifier 'ctime_r'; did you mean
'ctime_s'?
_GL_WARN_ON_USE (ctime_r, "ctime_r can overrun buffers in some cases - "
^~~~~~~
ctime_s
.\sys/socket.h(529,31): note: expanded from macro '_GL_WARN_ON_USE'
_GL_WARN_EXTERN_C __typeof__ (function) function \
^
The reason is that _GL_WARN_ON_USE works only for functions that are declared.
This patch fixes it.
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.
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 <time.h>
+ ]], [asctime_r ctime_r])
+
AC_REQUIRE([AC_C_RESTRICT])
AC_CACHE_CHECK([for TIME_UTC in <time.h>],
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- time: Fix compilation errors with clang/MSVC,
Bruno Haible <=