sys_ioctl: simplify

2020-08-16 Thread Bruno Haible
This use of AC_INCLUDES_DEFAULT looks like a typo. But it is an intentional
no-op. Weird.


2020-08-16  Bruno Haible  

sys_ioctl: Simplify.
* m4/sys_ioctl_h.m4 (gl_SYS_IOCTL_H): Remove confusing use of
AC_INCLUDES_DEFAULT.

diff --git a/m4/sys_ioctl_h.m4 b/m4/sys_ioctl_h.m4
index 303820e..cd2735e 100644
--- a/m4/sys_ioctl_h.m4
+++ b/m4/sys_ioctl_h.m4
@@ -1,4 +1,4 @@
-# sys_ioctl_h.m4 serial 10
+# sys_ioctl_h.m4 serial 11
 dnl Copyright (C) 2008-2020 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -22,7 +22,7 @@ AC_DEFUN([gl_SYS_IOCTL_H],
   [dnl We cannot use AC_CHECK_DECL because it produces its own messages.
AC_COMPILE_IFELSE(
  [AC_LANG_PROGRAM(
-[AC_INCLUDES_DEFAULT([#include ])],
+[[#include ]],
 [(void) ioctl;])],
  [gl_cv_decl_ioctl_in_sys_ioctl_h=yes],
  [gl_cv_decl_ioctl_in_sys_ioctl_h=no])




Assume autoconf >= 2.64

2020-08-16 Thread Bruno Haible
With Autoconf 2.63 and Automake 1.12.6 in $PATH, gnulib-tool fails:

  executing aclocal -I glm4
  glm4/00gnulib.m4:110: error: m4_defn: undefined macro: _AC_CHECK_DECL_BODY
  glm4/00gnulib.m4:110: the top level

This unintended regression was introduced on 2020-01-04, when 00gnulib.m4
started to reference _AC_CHECK_DECL_BODY (which was introduced in Autoconf
2.64).

The fact that no one reported this problem in 7 months means that we can
assume Autoconf >= 2.64.

Previously we only dared to assume Autoconf >= 2.63, because RHEL 6 / CentOS 6
ships with autoconf 2.63 [1]. But RHEL 6 will be end-of-life in November 2020
[2], and since it uses a kernel < 3.7, it has to be considered vulnerable
for uses not controlled by Russia ([3], [4] page 37). This explains why
no one reported the problem.

[1] https://repology.org/project/autoconf/versions
[2] https://en.wikipedia.org/wiki/Red_Hat_Enterprise_Linux
[3] 
https://www.fbi.gov/news/pressrel/press-releases/nsa-and-fbi-expose-russian-previously-undisclosed-malware-drovorub-in-cybersecurity-advisory
[4] 
https://media.defense.gov/2020/Aug/13/2002476465/-1/-1/0/CSA_DROVORUB_RUSSIAN_GRU_MALWARE_AUG_2020.PDF


2020-08-16  Bruno Haible  

Assume autoconf >= 2.64.
* gnulib-tool (DEFAULT_AUTOCONF_MINVERSION): Set to 2.64.
* DEPENDENCIES: Require Autoconf 2.64 or newer.
* NEWS: Mention the changed requirement.
* m4/00gnulib.m4 (_m4_divert_diversion, AC_DEFUN_ONCE): Remove macros.
* m4/gnulib-common.m4 (AS_VAR_IF, AS_VAR_COPY): Remove macros.
* m4/absolute-header.m4 (gl_ABSOLUTE_HEADER): Quote pushdef'ed
variables.
* m4/include_next.m4 (gl_NEXT_HEADERS_INTERNAL): Likewise.
* m4/warn-on-use.m4 (gl_WARN_ON_USE_PREPARE): Likewise.
* m4/warnings.m4 (gl_COMPILER_OPTION_IF): Likewise.
(gl_UNKNOWN_WARNINGS_ARE_ERRORS(C), gl_UNKNOWN_WARNINGS_ARE_ERRORS(C++),
gl_UNKNOWN_WARNINGS_ARE_ERRORS(Objective C)): Define through AC_DEFUN.
* m4/manywarnings.m4 (gl_MANYWARN_ALL_GCC(C), gl_MANYWARN_ALL_GCC(C++)):
Likewise.
* m4/iconv.m4 (AM_ICONV): Define through AC_DEFUN_ONCE directly.
* m4/libunistring.m4 (gl_LIBUNISTRING): Likewise.
* m4/configmake.m4: Update comment.

diff --git a/DEPENDENCIES b/DEPENDENCIES
index a7ca044..e7b9593 100644
--- a/DEPENDENCIES
+++ b/DEPENDENCIES
@@ -31,7 +31,7 @@ at any time.
   + Download:
 https://ftp.gnu.org/gnu/m4/
 
-* Autoconf 2.63 or newer.
+* Autoconf 2.64 or newer.
   + Mandatory.
   + Homepage:
 https://www.gnu.org/software/autoconf/
diff --git a/NEWS b/NEWS
index 8947747..ed88a7e 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,8 @@ Important general notes
 
 DateModules Changes
 
+2020-08-16  (all)   Automake >= 1.11 and Autoconf >= 2.64 are required.
+
 2019-12-11  Support for These modules are now supported in C++ mode as 
well.
 ISO C or POSIX  This means, while the autoconfiguration uses the C
 functions   compiler, the resulting header files and function
diff --git a/gnulib-tool b/gnulib-tool
index 20a2a3e..1ce9c30 100755
--- a/gnulib-tool
+++ b/gnulib-tool
@@ -48,11 +48,11 @@ nl='
 '
 IFS=" ""   $nl"
 
-# You can set AUTOCONFPATH to empty if autoconf 2.63 is already in your PATH.
+# You can set AUTOCONFPATH to empty if autoconf 2.64 is already in your PATH.
 AUTOCONFPATH=
 #case $USER in
 #  bruno )
-#AUTOCONFBINDIR=/arch/x86-linux/gnu-inst-autoconf/2.63/bin
+#AUTOCONFBINDIR=/arch/x86-linux/gnu-inst-autoconf/2.64/bin
 #AUTOCONFPATH="eval env PATH=${AUTOCONFBINDIR}:\$PATH "
 #;;
 #esac
@@ -1541,7 +1541,7 @@ func_determine_path_separator
 
   # Determine the minimum supported autoconf version from the project's
   # configure.ac.
-  DEFAULT_AUTOCONF_MINVERSION="2.63"
+  DEFAULT_AUTOCONF_MINVERSION="2.64"
   autoconf_minversion=
   configure_ac=
   if case "$mode" in import | add-import | remove-import | update) true;; *) 
false;; esac \
@@ -1588,8 +1588,8 @@ func_determine_path_separator
 autoconf_minversion=$DEFAULT_AUTOCONF_MINVERSION
   fi
   case "$autoconf_minversion" in
-1.* | 2.[0-5]* | 2.6[0-2]*)
-  func_fatal_error "minimum supported autoconf version is 2.63. Try adding 
AC_PREREQ([$DEFAULT_AUTOCONF_MINVERSION]) to your configure.ac." ;;
+1.* | 2.[0-5]* | 2.6[0-3]*)
+  func_fatal_error "minimum supported autoconf version is 2.64. Try adding 
AC_PREREQ([$DEFAULT_AUTOCONF_MINVERSION]) to your configure.ac." ;;
   esac
 
   # Remove trailing slashes from the directory names. This is necessary for
diff --git a/m4/00gnulib.m4 b/m4/00gnulib.m4
index 06eff4f..14628c3 100644
--- a/m4/00gnulib.m4
+++ b/m4/00gnulib.m4
@@ -1,44 +1,12 @@
-# 00gnulib.m4 serial 7
+# 00gnulib.m4 serial 8
 dnl Copyright (C) 2009-2020 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as 

Fix quoting of AC_LANG_PROGRAM arguments

2020-08-16 Thread Bruno Haible
Similarly the AC_LANG_PROGRAM arguments ought to be double-quoted.

Here, I did not find a bug. But it's better to be consistent, in order to
avoid bugs in future autoconf macros.


2020-08-16  Bruno Haible  

Fix quoting of AC_LANG_PROGRAM arguments.
* m4/fdopendir.m4 (gl_FUNC_FDOPENDIR): Quote the AC_LANG_PROGRAM
arguments through [[...]].
* m4/fpending.m4 (gl_FUNC_FPENDING): Likewise.
* m4/fpurge.m4 (gl_FUNC_FPURGE): Likewise.
* m4/fseeko.m4 (gl_FUNC_FSEEKO): Likewise.
* m4/ld-output-def.m4 (gl_LD_OUTPUT_DEF): Likewise.
* m4/ld-version-script.m4 (gl_LD_VERSION_SCRIPT): Likewise.
* m4/linkat.m4 (gl_FUNC_LINKAT): Likewise.
* m4/mountlist.m4 (gl_MOUNTLIST): Likewise.
* m4/sys_ioctl_h.m4 (gl_SYS_IOCTL_H): Likewise.
* m4/ungetc.m4 (gl_FUNC_UNGETC_WORKS): Likewise.
* m4/warn-on-use.m4 (gl_WARN_ON_USE_PREPARE): Likewise.
* m4/warnings.m4 (gl_COMPILER_OPTION_IF): Likewise.
* m4/wcstok.m4 (gl_FUNC_WCSTOK): Likewise.
* m4/wctype_h.m4 (gl_WCTYPE_H): Likewise.

diff --git a/m4/fdopendir.m4 b/m4/fdopendir.m4
index 454e9ad..9937a74 100644
--- a/m4/fdopendir.m4
+++ b/m4/fdopendir.m4
@@ -1,4 +1,4 @@
-# serial 13
+# serial 14
 # See if we need to provide fdopendir.
 
 dnl Copyright (C) 2009-2020 Free Software Foundation, Inc.
@@ -25,7 +25,8 @@ AC_DEFUN([gl_FUNC_FDOPENDIR],
   else
 AC_CACHE_CHECK([whether fdopendir works],
   [gl_cv_func_fdopendir_works],
-  [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
+  [AC_RUN_IFELSE(
+ [AC_LANG_PROGRAM([[
 #include 
 #include 
 #include 
@@ -37,12 +38,14 @@ extern
 # endif
 DIR *fdopendir (int);
 #endif
-]], [int result = 0;
- int fd = open ("conftest.c", O_RDONLY);
- if (fd < 0) result |= 1;
- if (fdopendir (fd)) result |= 2;
- if (close (fd)) result |= 4;
- return result;])],
+]],
+[[int result = 0;
+  int fd = open ("conftest.c", O_RDONLY);
+  if (fd < 0) result |= 1;
+  if (fdopendir (fd)) result |= 2;
+  if (close (fd)) result |= 4;
+  return result;
+]])],
  [gl_cv_func_fdopendir_works=yes],
  [gl_cv_func_fdopendir_works=no],
  [case "$host_os" in
diff --git a/m4/fpending.m4 b/m4/fpending.m4
index ea9725e..edabcec 100644
--- a/m4/fpending.m4
+++ b/m4/fpending.m4
@@ -1,4 +1,4 @@
-# serial 22
+# serial 23
 
 # Copyright (C) 2000-2001, 2004-2020 Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
@@ -25,7 +25,7 @@ AC_DEFUN([gl_FUNC_FPENDING],
   AC_CACHE_CHECK([for __fpending], [gl_cv_func___fpending],
 [
   AC_LINK_IFELSE(
-[AC_LANG_PROGRAM([$fp_headers],
+[AC_LANG_PROGRAM([[$fp_headers]],
[[return ! __fpending (stdin);]])],
 [gl_cv_func___fpending=yes],
 [gl_cv_func___fpending=no])
diff --git a/m4/fpurge.m4 b/m4/fpurge.m4
index 890c3e7..0796a6f 100644
--- a/m4/fpurge.m4
+++ b/m4/fpurge.m4
@@ -1,4 +1,4 @@
-# fpurge.m4 serial 10
+# fpurge.m4 serial 11
 dnl Copyright (C) 2007, 2009-2020 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -19,36 +19,36 @@ AC_DEFUN([gl_FUNC_FPURGE],
  [AC_LANG_PROGRAM(
 [[#include 
 ]],
-[FILE *f = fopen ("conftest.txt", "w+");
- if (!f)
-   return 1;
- if (fputc ('a', f) != 'a')
-   { fclose (f); return 2; }
- rewind (f);
- if (fgetc (f) != 'a')
-   { fclose (f); return 3; }
- if (fgetc (f) != EOF)
-   { fclose (f); return 4; }
- if (fpurge (f) != 0)
-   { fclose (f); return 5; }
- if (putc ('b', f) != 'b')
-   { fclose (f); return 6; }
- if (fclose (f) != 0)
-   return 7;
- if ((f = fopen ("conftest.txt", "r")) == NULL)
-   return 8;
- if (fgetc (f) != 'a')
-   { fclose (f); return 9; }
- if (fgetc (f) != 'b')
-   { fclose (f); return 10; }
- if (fgetc (f) != EOF)
-   { fclose (f); return 11; }
- if (fclose (f) != 0)
-   return 12;
- if (remove ("conftest.txt") != 0)
-   return 13;
- return 0;
-])],
+[[FILE *f = fopen ("conftest.txt", "w+");
+  if (!f)
+return 1;
+  if (fputc ('a', f) != 'a')
+{ fclose (f); return 2; }
+  rewind (f);
+  if (fgetc (f) != 'a')
+{ fclose (f); return 3; }
+  if (fgetc (f) != EOF)
+{ fclose (f); return 4; }
+  if (fpurge (f) != 0)
+{ fclose (f); return 5; }
+  if (putc ('b', f) != 'b')
+{ fclose (f);

Don't use Autoconf quadrigraphs

2020-08-16 Thread Bruno Haible
Autoconf quadrigraphs are obsolete for a long time already.
No more need for them, definitely, in Autoconf >= 2.64.


2020-08-16  Bruno Haible  

Don't use Autoconf quadrigraphs.
* m4/alloca.m4 (_AC_LIBOBJ_ALLOCA): Use '#' instead of the corresponding
Autoconf quadrigraph.
* m4/free.m4 (gl_FUNC_FREE): Likewise.
* m4/getloadavg.m4 (gl_PREREQ_GETLOADAVG): Likewise.
* m4/largefile.m4 (_AC_SYS_LARGEFILE_TEST_INCLUDES,
_AC_SYS_LARGEFILE_MACRO_VALUE): Likewise.
* m4/longlong.m4 (AC_TYPE_LONG_LONG_INT): Likewise.
* m4/math_h.m4 (gl_MATH_H): Likewise.
* m4/warn-on-use.m4 (gl_WARN_ON_USE_PREPARE): Likewise.

diff --git a/m4/alloca.m4 b/m4/alloca.m4
index b777f84..d841489 100644
--- a/m4/alloca.m4
+++ b/m4/alloca.m4
@@ -1,4 +1,4 @@
-# alloca.m4 serial 17
+# alloca.m4 serial 18
 dnl Copyright (C) 2002-2004, 2006-2007, 2009-2020 Free Software Foundation,
 dnl Inc.
 dnl This file is free software; the Free Software Foundation
@@ -102,7 +102,7 @@ AH_VERBATIM([STACK_DIRECTION],
 STACK_DIRECTION > 0 => grows toward higher addresses
 STACK_DIRECTION < 0 => grows toward lower addresses
 STACK_DIRECTION = 0 => direction of growth unknown */
-@%:@undef STACK_DIRECTION])dnl
+#undef STACK_DIRECTION])dnl
 AC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction)
 ])
 ])
diff --git a/m4/free.m4 b/m4/free.m4
index 02a8782..a62214c 100644
--- a/m4/free.m4
+++ b/m4/free.m4
@@ -24,12 +24,12 @@ AC_DEFUN([gl_FUNC_FREE],
*)
  AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
-  [[@%:@include ]],
-  [[@%:@if _POSIX_VERSION < 199009L && \
+  [[#include ]],
+  [[#if _POSIX_VERSION < 199009L && \
 (defined unix || defined _unix || defined _unix_ \
  || defined __unix || defined __unix__)
-  @%:@error "'free (NULL)' is not known to work"
-@%:@endif]])],
+  #error "'free (NULL)' is not known to work"
+#endif]])],
[gl_cv_func_free=yes],
[gl_cv_func_free=no])
  esac
diff --git a/m4/getloadavg.m4 b/m4/getloadavg.m4
index 8e96965..9fe328e 100644
--- a/m4/getloadavg.m4
+++ b/m4/getloadavg.m4
@@ -7,7 +7,7 @@
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
-#serial 9
+#serial 10
 
 # Autoconf defines AC_FUNC_GETLOADAVG, but that is obsolescent.
 # New applications should use gl_GETLOADAVG instead.
@@ -147,7 +147,7 @@ fi
 AC_CHECK_HEADERS([nlist.h],
 [AC_CHECK_MEMBERS([struct nlist.n_un.n_name],
   [], [],
-  [@%:@include ])
+  [#include ])
  AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]],
[[struct nlist x;
 #ifdef HAVE_STRUCT_NLIST_N_UN_N_NAME
diff --git a/m4/largefile.m4 b/m4/largefile.m4
index f7140dd..f4c5d3a 100644
--- a/m4/largefile.m4
+++ b/m4/largefile.m4
@@ -30,12 +30,12 @@ m4_version_prereq([2.70], [] ,[
 # _AC_SYS_LARGEFILE_TEST_INCLUDES
 # ---
 m4_define([_AC_SYS_LARGEFILE_TEST_INCLUDES],
-[@%:@include 
+[#include 
  /* Check that off_t can represent 2**63 - 1 correctly.
 We can't simply define LARGE_OFF_T to be 9223372036854775807,
 since some C++ compilers masquerading as C compilers
 incorrectly reject 9223372036854775807.  */
-@%:@define LARGE_OFF_T (((off_t) 1 << 31 << 31) - 1 + ((off_t) 1 << 31 << 31))
+#define LARGE_OFF_T (((off_t) 1 << 31 << 31) - 1 + ((off_t) 1 << 31 << 31))
   int off_t_is_large[[(LARGE_OFF_T % 2147483629 == 721
&& LARGE_OFF_T % 2147483647 == 1)
   ? 1 : -1]];[]dnl
@@ -54,7 +54,7 @@ m4_define([_AC_SYS_LARGEFILE_MACRO_VALUE],
 [AC_LANG_PROGRAM([$5], [$6])],
 [$3=no; break])
   m4_ifval([$6], [AC_LINK_IFELSE], [AC_COMPILE_IFELSE])(
-[AC_LANG_PROGRAM([@%:@define $1 $2
+[AC_LANG_PROGRAM([#define $1 $2
 $5], [$6])],
 [$3=$2; break])
   $3=unknown
diff --git a/m4/longlong.m4 b/m4/longlong.m4
index e878488..c0ab70a 100644
--- a/m4/longlong.m4
+++ b/m4/longlong.m4
@@ -1,4 +1,4 @@
-# longlong.m4 serial 18
+# longlong.m4 serial 19
 dnl Copyright (C) 1999-2007, 2009-2020 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -28,12 +28,12 @@ AC_DEFUN([AC_TYPE_LONG_LONG_INT],
   dnl nobody cross compiles for this platform as far as we know.
   AC_RUN_IFELSE(
 [AC_LANG_PROGRAM(
-   [[@%:@include 
- @%:@ifndef LLONG_MAX
- @%:@ define HALF \
+   [[#include 
+ #ifndef LLONG_MAX
+ # define HALF \
   (1LL << (sizeof (long long int) * CHAR_BIT - 2))
- @%:@ define LLONG_MAX (HALF - 1 + HALF)
- 

C++ tests: Fix link errors on MSVC

2020-08-16 Thread Bruno Haible
Link errors were accidentally introduced on 2020-05-31. Most of them were
fixed on 2020-06-27, but I forgot to test the C++ tests as well.


2020-08-16  Bruno Haible  

C++ tests: Fix link errors on MSVC (regression from 2020-05-31).
* modules/stdio-c++-tests (Makefile.am): Link test-stdio-c++ with
$(LIB_GETRANDOM), needed for the rpl_tmpfile symbol.
* modules/stdlib-c++-tests (Makefile.am): Link test-stdlib-c++ with
$(LIB_GETRANDOM), needed for the mkdtemp and mkstemp symbols.

diff --git a/modules/stdio-c++-tests b/modules/stdio-c++-tests
index 05e7544..df8ba4e 100644
--- a/modules/stdio-c++-tests
+++ b/modules/stdio-c++-tests
@@ -16,5 +16,5 @@ if ANSICXX
 TESTS += test-stdio-c++
 check_PROGRAMS += test-stdio-c++
 test_stdio_c___SOURCES = test-stdio-c++.cc test-stdio-c++2.cc
-test_stdio_c___LDADD = $(LDADD) $(LIBINTL) $(LIB_NANOSLEEP) $(LIB_EACCESS)
+test_stdio_c___LDADD = $(LDADD) $(LIBINTL) $(LIB_NANOSLEEP) $(LIB_EACCESS) 
$(LIB_GETRANDOM)
 endif
diff --git a/modules/stdlib-c++-tests b/modules/stdlib-c++-tests
index 634a2b3..1089c46 100644
--- a/modules/stdlib-c++-tests
+++ b/modules/stdlib-c++-tests
@@ -16,5 +16,5 @@ if ANSICXX
 TESTS += test-stdlib-c++
 check_PROGRAMS += test-stdlib-c++
 test_stdlib_c___SOURCES = test-stdlib-c++.cc test-stdlib-c++2.cc
-test_stdlib_c___LDADD = $(LDADD) $(LIBINTL) $(LIB_CLOCK_GETTIME) $(LIB_EACCESS)
+test_stdlib_c___LDADD = $(LDADD) $(LIBINTL) $(LIB_CLOCK_GETTIME) 
$(LIB_EACCESS) $(LIB_GETRANDOM)
 endif




improve clang support (33)

2020-08-16 Thread Bruno Haible
This set of patches fixes a number of warnings that I'm seeing when building
a POSIX testdir on MSVC/clang.


2020-08-16  Bruno Haible  

Fix "warning: 'WSASocketA' is deprecated: Use WSASocketW() instead".
* lib/socket.c: Use WSASocketW, not WSASocketA.

Fix "warning: format specifies type 'unsigned long'".
* tests/test-nonblocking-writer.h (main_writer_loop): Cast dbgfprintf
argument to match the format directive.

Fix "warning: no case matching constant switch condition '0'".
* tests/test-fcntl.c (check_flags): Add a 'default' case.

Fix "warning: integer overflow in expression".
* tests/test-strtol.c (main): Use an 'unsigned long' expression to
remove a 'long' overflow.

Fix "warning: "getpagesize" redefined".
* tests/test-getcwd.c (getpagesize): Don't redefine if defined as a
macro.

Fix "warning: implicitly declaring library function 'strncasecmp'".
* lib/strptime.c: Include .

Fix "warning: 'snprintf' macro redefined".
* lib/strerror_r.c (snprintf): Undefine before redefining.

Fix "warning: address of array 'locale' will always evaluate to 'true'".
* lib/nl_langinfo.c (ctype_codeset): Remove redundant NULL test.

Fix "warning: '__stat64' macro redefined".
* lib/glob.c (__stat64): Undefine also on MSVC/clang.

Fix "warning: 'format' attribute argument not supported: rpl_printf".
* lib/stdio.in.h (printf): Treat clang like GCC.

Fix "warning: attribute declaration must precede definition" with clang.
* lib/math.in.h (acosl, asinl, atanl, ceill, cosl, expl, fabsf, fabsl,
floorl, fmodl, frexpf, frexpl, hypotf, hypotl, ldexpf, ldexpl, logl,
log10l, modfl, sinl, sqrtl, tanl): Disable _GL_CXXALIASWARN invocation
on non-glibc systems.
* lib/netdb.in.h (gai_strerror): Likewise.
* lib/stdio.in.h (snprintf, vfscanf, vscanf, vsnprintf): Likewise.
* lib/sys_stat.in.h (fstat): Likewise.
* lib/utime.in.h (utime): Likewise.

Fix undesired warnings.
* lib/sys_select.in.h: Disable all _GL_WARN_ON_USE invocations with
clang.

>From e7307acb2016474fe0d5b12f1e659a661680ea99 Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Sun, 16 Aug 2020 13:00:05 +0200
Subject: [PATCH 01/13] Fix undesired warnings.

* lib/sys_select.in.h: Disable all _GL_WARN_ON_USE invocations with
clang.
---
 ChangeLog   | 6 ++
 lib/sys_select.in.h | 4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index af6b5d1..7761d3d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2020-08-16  Bruno Haible  
 
+	Fix undesired warnings.
+	* lib/sys_select.in.h: Disable all _GL_WARN_ON_USE invocations with
+	clang.
+
+2020-08-16  Bruno Haible  
+
 	C++ tests: Fix link errors on MSVC (regression from 2020-05-31).
 	* modules/stdio-c++-tests (Makefile.am): Link test-stdio-c++ with
 	$(LIB_GETRANDOM), needed for the rpl_tmpfile symbol.
diff --git a/lib/sys_select.in.h b/lib/sys_select.in.h
index 90bd540..d625d73 100644
--- a/lib/sys_select.in.h
+++ b/lib/sys_select.in.h
@@ -184,7 +184,7 @@ rpl_fd_isset (SOCKET fd, fd_set * set)
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef gethostname
 #   define gethostname gethostname_used_without_including_unistd_h
-#  else
+#  elif !defined __clang__
 _GL_WARN_ON_USE (gethostname,
  "gethostname() used without including ");
 #  endif
@@ -219,7 +219,7 @@ rpl_fd_isset (SOCKET fd, fd_set * set)
 #   define setsockopt  setsockopt_used_without_including_sys_socket_h
 #   undef shutdown
 #   define shutdownshutdown_used_without_including_sys_socket_h
-#  else
+#  elif !defined __clang__
 _GL_WARN_ON_USE (socket,
  "socket() used without including ");
 _GL_WARN_ON_USE (connect,
-- 
2.7.4

>From 9b2819782e058887d292a827952025c65d235a0b Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Sun, 16 Aug 2020 13:00:17 +0200
Subject: [PATCH 02/13] Fix "warning: attribute declaration must precede
 definition" with clang.

* lib/math.in.h (acosl, asinl, atanl, ceill, cosl, expl, fabsf, fabsl,
floorl, fmodl, frexpf, frexpl, hypotf, hypotl, ldexpf, ldexpl, logl,
log10l, modfl, sinl, sqrtl, tanl): Disable _GL_CXXALIASWARN invocation
on non-glibc systems.
* lib/netdb.in.h (gai_strerror): Likewise.
* lib/stdio.in.h (snprintf, vfscanf, vscanf, vsnprintf): Likewise.
* lib/sys_stat.in.h (fstat): Likewise.
* lib/utime.in.h (utime): Likewise.
---
 ChangeLog | 10 ++
 lib/math.in.h | 44 
 lib/netdb.in.h|  2 ++
 lib/stdio.in.h|  8 
 lib/sys_stat.in.h |  2 ++
 lib/utime.in.h|  2 ++
 6 files changed, 68 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 7761d3d..3a51cec 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2020-08-16  Brun

Re: improve clang support (3)

2020-08-16 Thread Bruno Haible
> clang supports __builtin_expect, even on Windows.

Another use of __builtin_expect is here:


2020-08-16  Bruno Haible  

avltreehash-list, rbtreehash-list: Optimize also on clang.
* lib/gl_anytreehash_list1.h (add_nodes_to_buckets): Use
__builtin_expect also on clang.

diff --git a/lib/gl_anytreehash_list1.h b/lib/gl_anytreehash_list1.h
index aba45d6..88fac00 100644
--- a/lib/gl_anytreehash_list1.h
+++ b/lib/gl_anytreehash_list1.h
@@ -340,7 +340,7 @@ add_nodes_to_buckets (gl_list_t list)
   return -1;
 }
 /* Tell GCC that the likely return value is 0.  */
-#if __GNUC__ >= 3
+#if (__GNUC__ >= 3) || (__clang_major__ >= 4)
 # define add_nodes_to_buckets(list) \
 __builtin_expect ((add_nodes_to_buckets) (list), 0)
 #endif




Re: improve clang support (22)

2020-08-16 Thread Bruno Haible
> clang supports expression statement syntax (a block inside parentheses) like
> GCC. This patch makes use of it.

Two further places where expression statements can be enabled in clang, for
better optimization:


2020-08-16  Bruno Haible  

setenv: Use tree code also with clang.
* lib/setenv.c (USE_TSEARCH): Treat clang like GCC.

2020-08-16  Bruno Haible  

math: Optimize signbit also on clang.
* lib/math.in.h (gl_signbitf, gl_signbitd, gl_signbitl): Optimize also
on clang.

>From ad3f6af5cea05a6aa9d6bf8588ef024d24f3b6ef Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Sun, 16 Aug 2020 18:39:29 +0200
Subject: [PATCH 1/2] math: Optimize signbit also on clang.

* lib/math.in.h (gl_signbitf, gl_signbitd, gl_signbitl): Optimize also
on clang.
---
 ChangeLog | 6 ++
 lib/math.in.h | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 81ed349..2e78c4f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2020-08-16  Bruno Haible  
 
+	math: Optimize signbit also on clang.
+	* lib/math.in.h (gl_signbitf, gl_signbitd, gl_signbitl): Optimize also
+	on clang.
+
+2020-08-16  Bruno Haible  
+
 	avltreehash-list, rbtreehash-list: Optimize also on clang.
 	* lib/gl_anytreehash_list1.h (add_nodes_to_buckets): Use
 	__builtin_expect also on clang.
diff --git a/lib/math.in.h b/lib/math.in.h
index 99b7e32..0f67127 100644
--- a/lib/math.in.h
+++ b/lib/math.in.h
@@ -2536,7 +2536,7 @@ _GL_WARN_REAL_FLOATING_DECL (isnan);
 _GL_EXTERN_C int gl_signbitf (float arg);
 _GL_EXTERN_C int gl_signbitd (double arg);
 _GL_EXTERN_C int gl_signbitl (long double arg);
-#  if __GNUC__ >= 2 && !defined __STRICT_ANSI__
+#  if (__GNUC__ >= 2 || defined __clang__) && !defined __STRICT_ANSI__
 #   define _GL_NUM_UINT_WORDS(type) \
   ((sizeof (type) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
 #   if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT && !defined gl_signbitf
-- 
2.7.4

>From 5a459e1cf0deb13b90313da377fe6cb2d8ccff73 Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Sun, 16 Aug 2020 18:39:33 +0200
Subject: [PATCH 2/2] setenv: Use tree code also with clang.

* lib/setenv.c (USE_TSEARCH): Treat clang like GCC.
---
 ChangeLog| 5 +
 lib/setenv.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 2e78c4f..b750f34 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2020-08-16  Bruno Haible  
 
+	setenv: Use tree code also with clang.
+	* lib/setenv.c (USE_TSEARCH): Treat clang like GCC.
+
+2020-08-16  Bruno Haible  
+
 	math: Optimize signbit also on clang.
 	* lib/math.in.h (gl_signbitf, gl_signbitd, gl_signbitl): Optimize also
 	on clang.
diff --git a/lib/setenv.c b/lib/setenv.c
index d03bc5a..aede703 100644
--- a/lib/setenv.c
+++ b/lib/setenv.c
@@ -72,7 +72,7 @@ __libc_lock_define_initialized (static, envlock)
values are from a small set.  Outside glibc this will eat up all
memory after a while.  */
 #if defined _LIBC || (defined HAVE_SEARCH_H && defined HAVE_TSEARCH \
-  && defined __GNUC__)
+  && (defined __GNUC__ || defined __clang__))
 # define USE_TSEARCH1
 # include 
 typedef int (*compar_fn_t) (const void *, const void *);
-- 
2.7.4



Re: improve clang support (23)

2020-08-16 Thread Bruno Haible
> clang also has the atomic built-ins and the asm support that GCC has.
> 
> 
> 2020-08-11  Bruno Haible  
> 
>   asyncsafe-spin: Use GCC built-ins also on clang.
>   * lib/asyncsafe-spin.c (asyncsafe_spin_init, do_lock, do_unlock): Use
>   the newer GCC built-ins also on clang.

The tests need an update for this change. And the same GCC built-ins can
also be used in the module 'pthread-spin'.


2020-08-16  Bruno Haible  

pthread-spin: Use GCC built-ins also on clang.
* lib/pthread-spin.c (pthread_spin_init, pthread_spin_lock,
pthread_spin_trylock, pthread_spin_unlock): Use the newer GCC built-ins
also on clang.

2020-08-16  Bruno Haible  

asyncsafe-spin tests: Update.
* tests/test-asyncsafe-spin2.c: Update to match the change in
lib/asyncsafe-spin.c from 2020-08-11.

>From dcc8b493adecff06096bb3516aac26d29012cf1a Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Sun, 16 Aug 2020 18:41:57 +0200
Subject: [PATCH 1/2] asyncsafe-spin tests: Update.

* tests/test-asyncsafe-spin2.c: Update to match the change in
lib/asyncsafe-spin.c from 2020-08-11.
---
 ChangeLog| 6 ++
 tests/test-asyncsafe-spin2.c | 3 ++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index b750f34..0f7ca8e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2020-08-16  Bruno Haible  
 
+	asyncsafe-spin tests: Update.
+	* tests/test-asyncsafe-spin2.c: Update to match the change in
+	lib/asyncsafe-spin.c from 2020-08-11.
+
+2020-08-16  Bruno Haible  
+
 	setenv: Use tree code also with clang.
 	* lib/setenv.c (USE_TSEARCH): Treat clang like GCC.
 
diff --git a/tests/test-asyncsafe-spin2.c b/tests/test-asyncsafe-spin2.c
index cb0364f..38d9324 100644
--- a/tests/test-asyncsafe-spin2.c
+++ b/tests/test-asyncsafe-spin2.c
@@ -36,7 +36,8 @@
 #define THREAD_COUNT 10
 
 /* Number of operations performed in each thread.  */
-#if !(defined _WIN32 && ! defined __CYGWIN__) && HAVE_PTHREAD_H && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) && !defined __ibmxl__
+#if !(defined _WIN32 && ! defined __CYGWIN__) && HAVE_PTHREAD_H && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || __clang_major__ >= 3) && !defined __ibmxl__
+
 /* The GCC built-ins are known to work fine.  */
 # define REPEAT_COUNT 5000
 #else
-- 
2.7.4

>From bed51ff8cc7bb755b32fa83c589436d8221380c6 Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Sun, 16 Aug 2020 18:42:02 +0200
Subject: [PATCH 2/2] pthread-spin: Use GCC built-ins also on clang.

* lib/pthread-spin.c (pthread_spin_init, pthread_spin_lock,
pthread_spin_trylock, pthread_spin_unlock): Use the newer GCC built-ins
also on clang.
---
 ChangeLog  |  7 +++
 lib/pthread-spin.c | 14 +-
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0f7ca8e..b97fcf7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2020-08-16  Bruno Haible  
 
+	pthread-spin: Use GCC built-ins also on clang.
+	* lib/pthread-spin.c (pthread_spin_init, pthread_spin_lock,
+	pthread_spin_trylock, pthread_spin_unlock): Use the newer GCC built-ins
+	also on clang.
+
+2020-08-16  Bruno Haible  
+
 	asyncsafe-spin tests: Update.
 	* tests/test-asyncsafe-spin2.c: Update to match the change in
 	lib/asyncsafe-spin.c from 2020-08-11.
diff --git a/lib/pthread-spin.c b/lib/pthread-spin.c
index c131050..c343f9d 100644
--- a/lib/pthread-spin.c
+++ b/lib/pthread-spin.c
@@ -68,9 +68,11 @@ pthread_spin_destroy (pthread_spinlock_t *lock)
 /* We don't use the C11  (available in GCC >= 4.9) because it would
require to link with -latomic.  */
 
-# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)
-/* Use GCC built-ins (available in GCC >= 4.7) that operate on the first 32-bit
-   word of the lock.
+# if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) \
+  || __clang_major > 3 || (__clang_major__ == 3 && __clang_minor__ >= 1)) \
+ && !defined __ibmxl__
+/* Use GCC built-ins (available in GCC >= 4.7 and clang >= 3.1) that operate on
+   the first byte of the lock.
Documentation:
  */
 
@@ -162,8 +164,10 @@ pthread_spin_destroy (pthread_spinlock_t *lock)
   return 0;
 }
 
-# elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
-/* Use GCC built-ins (available in GCC >= 4.1).
+# elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) \
+|| __clang_major__ >= 3) \
+   && !defined __ibmxl__
+/* Use GCC built-ins (available in GCC >= 4.1 and clang >= 3.0).
Documentation:
  */
 
-- 
2.7.4



Re: improve clang support (25)

2020-08-16 Thread Bruno Haible
> Where does clang support the 'restrict' and '__restrict' keywords? It's
> like with GCC >= 3.1:
> 
>C mode C++ mode
> 
> T*__restrict   supported  supported
> [__restrict]   supported  error
> T*restrict supported  error
> [restrict] supported  error

'__restrict' is also dealt with in a couple of other files. Here are the
corresponding updates.


2020-08-16  Bruno Haible  

Use __restrict also on clang.
* lib/argp.h (__restrict): Don't define as a macro on clang >= 3.
* lib/glob.in.h (_Restrict_): Use __restrict on clang >= 3.
* lib/unitypes.in.h (_UC_RESTRICT): Likewise.

diff --git a/lib/argp.h b/lib/argp.h
index 808c900..c71dd96 100644
--- a/lib/argp.h
+++ b/lib/argp.h
@@ -39,7 +39,8 @@
Other compilers use __restrict, __restrict__, and _Restrict, and
'configure' might #define 'restrict' to those words.  */
 #ifndef __restrict
-# if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__))
+# if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__) \
+|| __clang_major__ >= 3)
 #  if 199901L <= __STDC_VERSION__
 #   define __restrict restrict
 #  else
diff --git a/lib/glob.in.h b/lib/glob.in.h
index 7061a25..d1c0733 100644
--- a/lib/glob.in.h
+++ b/lib/glob.in.h
@@ -45,7 +45,9 @@
'configure' might #define 'restrict' to those words, so pick a
different name.  */
 #ifndef _Restrict_
-# if defined __restrict || 2 < __GNUC__ + (95 <= __GNUC_MINOR__)
+# if defined __restrict \
+ || 2 < __GNUC__ + (95 <= __GNUC_MINOR__) \
+ || __clang_major__ >= 3
 #  define _Restrict_ __restrict
 # elif 199901L <= __STDC_VERSION__ || defined restrict
 #  define _Restrict_ restrict
diff --git a/lib/unitypes.in.h b/lib/unitypes.in.h
index b11326d..63d0fe3 100644
--- a/lib/unitypes.in.h
+++ b/lib/unitypes.in.h
@@ -47,7 +47,9 @@ typedef uint32_t ucs4_t;
pass a pointer to a different object in the specified pointer argument
than in the other pointer arguments.  */
 #ifndef _UC_RESTRICT
-# if defined __restrict || 2 < __GNUC__ + (95 <= __GNUC_MINOR__)
+# if defined __restrict \
+ || 2 < __GNUC__ + (95 <= __GNUC_MINOR__) \
+ || __clang_major__ >= 3
 #  define _UC_RESTRICT __restrict
 # elif 199901L <= __STDC_VERSION__ || defined restrict
 #  define _UC_RESTRICT restrict




Re: improve clang support (33)

2020-08-16 Thread Bruno Haible
>   Fix "warning: 'format' attribute argument not supported: rpl_printf".
>   * lib/stdio.in.h (printf): Treat clang like GCC.

Similarly, in order to preserve  __attribute__ ((scanf, )): 'scanf'
must be mapped to '__scanf__', not 'rpl_scanf'.


2020-08-16  Bruno Haible  

stdio: Don't break attribute 'scanf' on clang.
* lib/stdio.in.h (scanf): Treat clang like GCC.

diff --git a/lib/stdio.in.h b/lib/stdio.in.h
index d55ef82..0db5111 100644
--- a/lib/stdio.in.h
+++ b/lib/stdio.in.h
@@ -1143,7 +1143,7 @@ _GL_WARN_ON_USE (renameat, "renameat is not portable - "
 
 #if @GNULIB_SCANF@
 # if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@
-#  if defined __GNUC__
+#  if defined __GNUC__ || defined __clang__
 #   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #undef scanf
 /* Don't break __attribute__((format(scanf,M,N))).  */




Re: improve clang support (33)

2020-08-16 Thread Bruno Haible
>   Fix "warning: implicitly declaring library function 'strncasecmp'".
>   * lib/strptime.c: Include .

Similarly, to fix this warning:

../../gllib/argp-help.c:783:16: warning: implicitly declaring library function 
'strcasecmp' with type 'int (const char *, const char *)' 
[-Wimplicit-function-declaration]


2020-08-16  Bruno Haible  

Fix "warning: implicitly declaring library function 'strcasecmp'".
* lib/argp-help.c: Include .

diff --git a/lib/argp-help.c b/lib/argp-help.c
index 9c95c16..73987ba 100644
--- a/lib/argp-help.c
+++ b/lib/argp-help.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 




improve clang support (34)

2020-08-16 Thread Bruno Haible
clang has #include_next.


2020-08-16  Bruno Haible  

absolute-header: Add support for clang.
* modules/absolute-header (Makefile.am): Include '__clang__' in the
HAVE_INCLUDE_NEXT expression.

diff --git a/modules/absolute-header b/modules/absolute-header
index 491d3d2..1866348 100644
--- a/modules/absolute-header
+++ b/modules/absolute-header
@@ -12,7 +12,7 @@ Makefile.am:
 # Use this preprocessor expression to decide whether #include_next works.
 # Do not rely on a 'configure'-time test for this, since the expression
 # might appear in an installed header, which is used by some other compiler.
-HAVE_INCLUDE_NEXT = (__GNUC__ || 6000 <= __DECC_VER)
+HAVE_INCLUDE_NEXT = (__GNUC__ || __clang__ || 6000 <= __DECC_VER)
 
 Include:
 




improve clang support (35)

2020-08-16 Thread Bruno Haible
clang (at least in version >= 4), in C++ mode, supports the 'throw ()' 
declaration
on functions, and uses it to optimize try/catch statements at the caller site.


2020-08-16  Bruno Haible  

Use 'throw ()' for optimization in C++ mode also on clang.
* lib/cdefs.h (__THROW): Define to 'throw ()' also on clang.
* lib/getopt-cdefs.in.h (__THROW): Likewise.
* lib/md5.h (__THROW): Likewise.

diff --git a/lib/cdefs.h b/lib/cdefs.h
index dfa935f..b7f60c1 100644
--- a/lib/cdefs.h
+++ b/lib/cdefs.h
@@ -85,7 +85,7 @@
 #  define __NTH(fct)   __attribute__ ((__nothrow__ __LEAF)) fct
 #  define __NTHNL(fct)  __attribute__ ((__nothrow__)) fct
 # else
-#  if defined __cplusplus && __GNUC_PREREQ (2,8)
+#  if defined __cplusplus && (__GNUC_PREREQ (2,8) || __clang_major >= 4)
 #   define __THROW throw ()
 #   define __THROWNL   throw ()
 #   define __NTH(fct)  __LEAF_ATTR fct throw ()
diff --git a/lib/getopt-cdefs.in.h b/lib/getopt-cdefs.in.h
index 89a7b85..641e5e9 100644
--- a/lib/getopt-cdefs.in.h
+++ b/lib/getopt-cdefs.in.h
@@ -57,7 +57,7 @@
 #endif
 
 #ifndef __THROW
-# if defined __cplusplus && __GNUC_PREREQ (2,8)
+# if defined __cplusplus && (__GNUC_PREREQ (2,8) || __clang_major__ >= 4)
 #  define __THROW   throw ()
 # else
 #  define __THROW
diff --git a/lib/md5.h b/lib/md5.h
index 0c8b929..4631035 100644
--- a/lib/md5.h
+++ b/lib/md5.h
@@ -40,7 +40,7 @@
 #endif
 
 #ifndef __THROW
-# if defined __cplusplus && __GNUC_PREREQ (2,8)
+# if defined __cplusplus && (__GNUC_PREREQ (2,8) || __clang_major__ >= 4)
 #  define __THROW   throw ()
 # else
 #  define __THROW




improve clang support (36)

2020-08-16 Thread Bruno Haible
clang has _Static_assert and, in C++ mode, also 'static_assert' (at least in
clang >= 4). Gnulib can make use of it.


2020-08-16  Bruno Haible  

Use _Static_assert and static_assert primitives when present on clang.
* lib/cdefs.h (_Static_assert): Don't define as a macro on clang.
* lib/verify.h (_GL_HAVE__STATIC_ASSERT, _GL_HAVE__STATIC_ASSERT1,
_GL_HAVE_STATIC_ASSERT1): Define as appropriate on clang.

diff --git a/lib/cdefs.h b/lib/cdefs.h
index b7f60c1..67ad180 100644
--- a/lib/cdefs.h
+++ b/lib/cdefs.h
@@ -465,7 +465,8 @@
 
 #if (!defined _Static_assert && !defined __cplusplus \
  && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
- && (!__GNUC_PREREQ (4, 6) || defined __STRICT_ANSI__))
+ && (!(__GNUC_PREREQ (4, 6) || __clang_major__ >= 4) \
+ || defined __STRICT_ANSI__))
 # define _Static_assert(expr, diagnostic) \
 extern int (*__Static_assert_function (void)) \
   [!!sizeof (struct { int __error_if_negative: (expr) ? 2 : -1; })]
diff --git a/lib/verify.h b/lib/verify.h
index 58172f3..0ba8d57 100644
--- a/lib/verify.h
+++ b/lib/verify.h
@@ -23,11 +23,15 @@
 
 /* Define _GL_HAVE__STATIC_ASSERT to 1 if _Static_assert (R, DIAGNOSTIC)
works as per C11.  This is supported by GCC 4.6.0 and later, in C
-   mode.
+   mode, and by clang (also in C++ mode).
 
Define _GL_HAVE__STATIC_ASSERT1 to 1 if _Static_assert (R) works as
-   per C2X, and define _GL_HAVE_STATIC_ASSERT1 if static_assert (R)
-   works as per C++17.  This is supported by GCC 9.1 and later.
+   per C2X.  This is supported by GCC 9.1 and later, and by clang in
+   C++1z mode.
+
+   Define _GL_HAVE_STATIC_ASSERT1 if static_assert (R) works as per
+   C++17.  This is supported by GCC 9.1 and later, and by clang in
+   C++1z mode.
 
Support compilers claiming conformance to the relevant standard,
and also support GCC when not pedantic.  If we were willing to slow
@@ -35,7 +39,8 @@
since this affects only the quality of diagnostics, why bother?  */
 #ifndef __cplusplus
 # if (201112L <= __STDC_VERSION__ \
-  || (!defined __STRICT_ANSI__ && 4 < __GNUC__ + (6 <= __GNUC_MINOR__)))
+  || (!defined __STRICT_ANSI__ \
+  && (4 < __GNUC__ + (6 <= __GNUC_MINOR__) || 4 <= __clang_major__)))
 #  define _GL_HAVE__STATIC_ASSERT 1
 # endif
 # if (202000L <= __STDC_VERSION__ \
@@ -43,7 +48,15 @@
 #  define _GL_HAVE__STATIC_ASSERT1 1
 # endif
 #else
-# if 201703L <= __cplusplus || 9 <= __GNUC__
+# if 4 <= __clang_major__
+#  define _GL_HAVE__STATIC_ASSERT 1
+# endif
+# if 4 <= __clang_major__ && 201411 <= __cpp_static_assert
+#  define _GL_HAVE__STATIC_ASSERT1 1
+# endif
+# if 201703L <= __cplusplus \
+ || 9 <= __GNUC__ \
+ || (4 <= __clang_major__ && 201411 <= __cpp_static_assert)
 #  define _GL_HAVE_STATIC_ASSERT1 1
 # endif
 #endif




improve clang support (37)

2020-08-16 Thread Bruno Haible
clang supports struct members whose type is an enum, with a bitfield width.


2020-08-16  Bruno Haible  

regex: Use space optimization also with clang.
* lib/regex_internal.h (re_token_t): Use a single byte for the type also
with clang.

diff --git a/lib/regex_internal.h b/lib/regex_internal.h
index df5303c..dbc503c 100644
--- a/lib/regex_internal.h
+++ b/lib/regex_internal.h
@@ -335,7 +335,7 @@ typedef struct
 Idx idx;   /* for BACK_REF */
 re_context_type ctx_type;  /* for ANCHOR */
   } opr;
-#if __GNUC__ >= 2 && !defined __STRICT_ANSI__
+#if (__GNUC__ >= 2 || defined __clang__) && !defined __STRICT_ANSI__
   re_token_type_t type : 8;
 #else
   re_token_type_t type;




improve clang support (38)

2020-08-16 Thread Bruno Haible
clang support the array initialization shorthand syntax
  [ first ... last ] = value
,
at least in clang >= 4.


2020-08-16  Bruno Haible  

regex: Use initializer shorthand syntax also with clang.
* lib/regcomp.c (utf8_sb_map): Use the initializer shorthand syntax also
with clang.

diff --git a/lib/regcomp.c b/lib/regcomp.c
index 93bb0a0..692928b 100644
--- a/lib/regcomp.c
+++ b/lib/regcomp.c
@@ -558,7 +558,7 @@ weak_alias (__regerror, regerror)
 static const bitset_t utf8_sb_map =
 {
   /* Set the first 128 bits.  */
-# if defined __GNUC__ && !defined __STRICT_ANSI__
+# if (defined __GNUC__ || __clang_major__ >= 4) && !defined __STRICT_ANSI__
   [0 ... 0x80 / BITSET_WORD_BITS - 1] = BITSET_WORD_MAX
 # else
 #  if 4 * BITSET_WORD_BITS < ASCII_CHARS




improve clang support (39)

2020-08-16 Thread Bruno Haible
clang supports referencing a symbol under a different name at the assembler
level, like GCC. Also it supports __USER_LABEL_PREFIX__, like GCC (this is
an underscore on 32-bit native Windows, but empty on 64-bit native Windows).


2020-08-16  Bruno Haible  

libc-config: Enable __REDIRECT macro also on clang.
* lib/cdefs.h (__REDIRECT, __REDIRECT_NTH, __REDIRECT_NTHNL, __ASMNAME,
__ASMNAME2): Define on clang like on GCC.

diff --git a/lib/cdefs.h b/lib/cdefs.h
index 67ad180..74da734 100644
--- a/lib/cdefs.h
+++ b/lib/cdefs.h
@@ -194,7 +194,7 @@
Example:
int __REDIRECT(setpgrp, (__pid_t pid, __pid_t pgrp), setpgid); */
 
-#if defined __GNUC__ && __GNUC__ >= 2
+#if (defined __GNUC__ && __GNUC__ >= 2) || (__clang_major__ >= 4)
 
 # define __REDIRECT(name, proto, alias) name proto __asm__ (__ASMNAME (#alias))
 # ifdef __cplusplus




improve clang support (40)

2020-08-16 Thread Bruno Haible
clang support #warning.


2020-08-16  Bruno Haible  

argp: Emit a warning also with clang.
* lib/argp-help.c (__argp_short_program_name): Use #warning also on
clang.

diff --git a/lib/argp-help.c b/lib/argp-help.c
index 9c95c16..80be8c8 100644
--- a/lib/argp-help.c
+++ b/lib/argp-help.c
@@ -1722,7 +1722,7 @@ __argp_short_program_name (void)
   /* FIXME: What now? Miles suggests that it is better to use NULL,
  but currently the value is passed on directly to fputs_unlocked,
  so that requires more changes. */
-# if __GNUC__
+# if __GNUC__ || (__clang_major__ >= 4)
 #  warning No reasonable value to return
 # endif /* __GNUC__ */
   return "";




improve clang support (41)

2020-08-16 Thread Bruno Haible
Unlike MSVC, clang groks the expression 0.0L/0.0L.


2020-08-16  Bruno Haible  

log2l: Disable MSVC workaround on clang.
* lib/log2l.c (log2l): On clang, use the expression 0.0L/0.0L.

diff --git a/lib/log2l.c b/lib/log2l.c
index 8634026..ad47379 100644
--- a/lib/log2l.c
+++ b/lib/log2l.c
@@ -52,7 +52,7 @@ log2l (long double x)
   else
 {
   /* Return NaN.  */
-#if defined _MSC_VER || (defined __sgi && !defined __GNUC__)
+#if (defined _MSC_VER && !defined __clang__) || (defined __sgi && !defined 
__GNUC__)
   static long double zero;
   return zero / zero;
 #else




improve clang support (42)

2020-08-16 Thread Bruno Haible
clang emits several hundred "warning: division by zero is undefined" warnings
when compiling test-intprops.c. This patch fixes it.


2020-08-16  Bruno Haible  

intprops: Avoid bogus "warning: division by zero is undefined" on clang.
* lib/intprops.h (_GL__GENERIC_BOGUS): Define to 1 on clang.

diff --git a/lib/intprops.h b/lib/intprops.h
index 2ab1b6f..6ee6324 100644
--- a/lib/intprops.h
+++ b/lib/intprops.h
@@ -396,7 +396,7 @@
For now, assume all versions of GCC-like compilers generate bogus
warnings for _Generic.  This matters only for compilers that
lack relevant builtins.  */
-#if __GNUC__
+#if __GNUC__ || defined __clang__
 # define _GL__GENERIC_BOGUS 1
 #else
 # define _GL__GENERIC_BOGUS 0




improve clang support (43)

2020-08-16 Thread Bruno Haible
clang can inline, like GCC. It also supports the '__inline' and '__inline__'
keywords.


2020-08-16  Bruno Haible  

nstrftime: Guide inlining also on clang.
* lib/nstrftime.c (iso_week_days): Inline also on clang.

diff --git a/lib/nstrftime.c b/lib/nstrftime.c
index 28bc42f..580224d 100644
--- a/lib/nstrftime.c
+++ b/lib/nstrftime.c
@@ -368,7 +368,7 @@ tm_diff (const struct tm *a, const struct tm *b)
 #define ISO_WEEK1_WDAY 4 /* Thursday */
 #define YDAY_MINIMUM (-366)
 static int iso_week_days (int, int);
-#ifdef __GNUC__
+#if defined __GNUC__ || defined __clang__
 __inline__
 #endif
 static int




improve clang support (44)

2020-08-16 Thread Bruno Haible
With clang, verify_stmt works well enough (as evidenced by the unit test).


2020-08-16  Bruno Haible  

intprops test: Strengthen on clang.
* tests/test-intprops.c (VERIFY): Use verify_stmt.

diff --git a/tests/test-intprops.c b/tests/test-intprops.c
index a56b18e..51477fd 100644
--- a/tests/test-intprops.c
+++ b/tests/test-intprops.c
@@ -48,7 +48,7 @@
These tests should be checkable via 'verify' rather than 'ASSERT', but
using 'verify' would run into a bug with HP-UX 11.23 cc; see
.  */
-#if __GNUC__ || __SUNPRO_C
+#if __GNUC__ || __clang__ || __SUNPRO_C
 # define VERIFY(x) verify_stmt (x)
 #else
 # define VERIFY(x) ASSERT (x)




[PATCH] time_rz: fix issues with mktime_z failures

2020-08-16 Thread Paul Eggert
* lib/time_rz.c (mktime_z): Do not update *TM if revert_tz fails.
Use a cheaper tm_yday test for failed mktime.
---
 ChangeLog |  6 ++
 lib/time_rz.c | 26 +-
 2 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0810c1106..2e4651751 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2020-08-16  Paul Eggert  
+
+   time_rz: fix issues with mktime_z failures
+   * lib/time_rz.c (mktime_z): Do not update *TM if revert_tz fails.
+   Use a cheaper tm_yday test for failed mktime.
+
 2020-08-16  Bruno Haible  
 
intprops test: Strengthen on clang.
diff --git a/lib/time_rz.c b/lib/time_rz.c
index 0a8aac999..8ed3c4443 100644
--- a/lib/time_rz.c
+++ b/lib/time_rz.c
@@ -327,17 +327,25 @@ mktime_z (timezone_t tz, struct tm *tm)
   timezone_t old_tz = set_tz (tz);
   if (old_tz)
 {
-  time_t t = mktime (tm);
-#if HAVE_TM_ZONE || HAVE_TZNAME
-  time_t badtime = -1;
   struct tm tm_1;
-  if ((t != badtime
-   || (localtime_r (&t, &tm_1) && equal_tm (tm, &tm_1)))
-  && !save_abbr (tz, tm))
-t = badtime;
+  tm_1.tm_sec = tm->tm_sec;
+  tm_1.tm_min = tm->tm_min;
+  tm_1.tm_hour = tm->tm_hour;
+  tm_1.tm_mday = tm->tm_mday;
+  tm_1.tm_mon = tm->tm_mon;
+  tm_1.tm_year = tm->tm_year;
+  tm_1.tm_yday = -1;
+  tm_1.tm_isdst = tm->tm_isdst;
+  time_t t = mktime (&tm_1);
+  bool ok = 0 <= tm_1.tm_yday;
+#if HAVE_TM_ZONE || HAVE_TZNAME
+  ok = ok && save_abbr (tz, &tm_1);
 #endif
-  if (revert_tz (old_tz))
-return t;
+  if (revert_tz (old_tz) && ok)
+{
+  *tm = tm_1;
+  return t;
+}
 }
   return -1;
 }
-- 
2.25.4




Re: improve clang support (34)

2020-08-16 Thread Paul Smith
On Sun, 2020-08-16 at 18:55 +0200, Bruno Haible wrote:
> +HAVE_INCLUDE_NEXT = (__GNUC__ || __clang__ || 6000 <= __DECC_VER)

Just wondering, are these changes for the sake of documentation, or are
they really needed (do you see problems without them)?

In my experience with clang, it always defines both __clang__ and
__GNUC__ so changes like this don't change behavior.

I definitely have no objection to adding them; I'm curious if there's
something going on here I'm not familiar with.

  $ clang -x c /dev/null -dM -E | grep -i gnu
  #define __GNUC_MINOR__ 2
  #define __GNUC_PATCHLEVEL__ 1
  #define __GNUC_STDC_INLINE__ 1
  #define __GNUC__ 4
  #define __gnu_linux__ 1





Re: improve clang support (34)

2020-08-16 Thread Bruno Haible
Hi Paul,

Paul Smith wrote:
> > +HAVE_INCLUDE_NEXT = (__GNUC__ || __clang__ || 6000 <= __DECC_VER)
> 
> Just wondering, are these changes for the sake of documentation, or are
> they really needed (do you see problems without them)?

This Makefile variable HAVE_INCLUDE_NEXT is not used in Gnulib, but some
packages may be using it. I included this module in the clang support for
completeness.

> In my experience with clang, it always defines both __clang__ and
> __GNUC__ so changes like this don't change behavior.

clang for Windows defines __clang__ but does not define __GNUC__. [1]

Bruno

[1] https://lists.gnu.org/archive/html/bug-gnulib/2020-08/msg00038.html




Re: improve clang support (35)

2020-08-16 Thread Florian Weimer
* Bruno Haible:

> clang (at least in version >= 4), in C++ mode, supports the 'throw
> ()' declaration on functions, and uses it to optimize try/catch
> statements at the caller site.

I think throw() has been removed from C++20:
  
  
  

So it will soon break again.



Re: improve clang support (34)

2020-08-16 Thread Paul Smith
On Sun, 2020-08-16 at 22:54 +0200, Bruno Haible wrote:
> This Makefile variable HAVE_INCLUDE_NEXT is not used in Gnulib, but
> some packages may be using it. I included this module in the clang
> support for completeness.

Thanks; I wasn't really asking about this particular change per se,
rather the set of changes that have been made that are similar to this.

> > In my experience with clang, it always defines both __clang__ and
> > __GNUC__ so changes like this don't change behavior.
> 
> clang for Windows defines __clang__ but does not define __GNUC__. [1]

Aha!  The clang devs are constantly... "surprising" me with their
choices in these areas.  I learned something so it was worth asking :).

Cheers!




Re: C++ throw() clause

2020-08-16 Thread Bruno Haible
Hi Florian,

> > clang (at least in version >= 4), in C++ mode, supports the 'throw
> > ()' declaration on functions, and uses it to optimize try/catch
> > statements at the caller site.
> 
> I think throw() has been removed from C++20:
>   
>   
>   
> 
> So it will soon break again.

Thanks for the heads-up. But g++ 10.2.0 still understands this
"removed" syntax:

 nothrow.cc 
extern int validate (int x) throw ();
extern void err (int e);

int foo (int x, int y)
{
  try { validate (x); } catch (int e) { err (e); }
  try { validate (y); } catch (int e) { err (e); }
  return x + y;
}

$ g++ -O2 -S -std=c++20 -Wall nothrow.cc


And glibc/misc/sys/cdefs.h has not been updated yet. Is it certain
that GCC and the GCC compatible compilers (clang, icc, etc.) will
continue to support 'throw ()'?

Bruno




Re: C++ throw() clause

2020-08-16 Thread Jeffrey Walton
On Sun, Aug 16, 2020 at 7:14 PM Bruno Haible  wrote:
>
> Hi Florian,
>
> > > clang (at least in version >= 4), in C++ mode, supports the 'throw
> > > ()' declaration on functions, and uses it to optimize try/catch
> > > statements at the caller site.
> >
> > I think throw() has been removed from C++20:
> >
> >   
> >   
> >
> > So it will soon break again.
>
> Thanks for the heads-up. But g++ 10.2.0 still understands this
> "removed" syntax:
>
>  nothrow.cc 
> extern int validate (int x) throw ();
> extern void err (int e);
>
> int foo (int x, int y)
> {
>   try { validate (x); } catch (int e) { err (e); }
>   try { validate (y); } catch (int e) { err (e); }
>   return x + y;
> }
> 
> $ g++ -O2 -S -std=c++20 -Wall nothrow.cc
> 
>
> And glibc/misc/sys/cdefs.h has not been updated yet. Is it certain
> that GCC and the GCC compatible compilers (clang, icc, etc.) will
> continue to support 'throw ()'?

Exception specifications have been deprecated for about a decade.
Prior to deprecation they fell out of favor and were not recommended.
Also see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3051.html.

About the only place I see them in modern software is
'noexcept(false)' when a destructor throws.

Jeff