Building a Gnulib testdir on macOS 12.5, I see many compilation errors like
this one:

../../gltests/test-dirent-c++.cc:28:1: error: expected expression
SIGNATURE_CHECK (GNULIB_NAMESPACE::opendir, DIR *, (const char *));
^
../../gltests/signature.h:39:3: note: expanded from macro 'SIGNATURE_CHECK'
  SIGNATURE_CHECK1 (fn, ret, args, __LINE__)
  ^
../../gltests/signature.h:44:3: note: expanded from macro 'SIGNATURE_CHECK1'
  SIGNATURE_CHECK2 (fn, ret, args, id) /* macroexpand line */
  ^
../../gltests/signature.h:46:3: note: expanded from macro 'SIGNATURE_CHECK2'
  _GL_UNUSED static ret (*signature_check ## id) args = fn
  ^
../config.h:7536:20: note: expanded from macro '_GL_UNUSED'
#define _GL_UNUSED _GL_ATTRIBUTE_MAYBE_UNUSED
                   ^
../config.h:7523:40: note: expanded from macro '_GL_ATTRIBUTE_MAYBE_UNUSED'
#   define _GL_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]]
                                       ^

The macroexpanded line is:

[[__maybe_unused__]] static DIR * (*signature_check28) (const char *) = 
gnulib::Opendir;

The fix is to define _GL_ATTRIBUTE_MAYBE_UNUSED differently, with this
compiler.


2023-02-09  Bruno Haible  <[email protected]>

        Fix compilation errors in C++ mode on macOS 12.5.
        * m4/gnulib-common.m4 (gl_COMMON_BODY): Don't define
        _GL_ATTRIBUTE_MAYBE_UNUSED to [[__maybe_unused__]] if the compiler is
        an Apple variant of clang.

diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4
index c0181abdc5..1e6748ed8c 100644
--- a/m4/gnulib-common.m4
+++ b/m4/gnulib-common.m4
@@ -1,4 +1,4 @@
-# gnulib-common.m4 serial 80
+# gnulib-common.m4 serial 81
 dnl Copyright (C) 2007-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -356,7 +356,7 @@ AC_DEFUN([gl_COMMON_BODY], [
    [[__maybe_unused__]] nevertheless produces a warning.  */
 #ifndef _GL_ATTRIBUTE_MAYBE_UNUSED
 # if defined __clang__ && defined __cplusplus
-#  if __clang_major__ >= 10
+#  if !defined __apple_build_version__ && __clang_major__ >= 10
 #   define _GL_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]]
 #  endif
 # elif defined __has_c_attribute




Reply via email to