bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Avoid suboptimal definition of _GL_HAS_ATTRIBUTE on FreeBSD/sparc64


From: Bruno Haible
Subject: Avoid suboptimal definition of _GL_HAS_ATTRIBUTE on FreeBSD/sparc64
Date: Fri, 09 Feb 2024 19:17:33 +0100

Compiling GNU poke 3.90.2 on FreeBSD 12.2/sparc64, I see several of these
warnings:

In file included from ../../jitter/jitterc/jitterc-generate.h:27,
                 from ../../jitter/jitterc/jitterc-generate.c:38:
./config-private/config.h:1801:1: warning: "_GL_HAS_ATTRIBUTE" redefined
In file included from ../../jitter/jitterc/jitterc-generate.c:23:
./config-private/config.h:1803:1: warning: this is the location of the previous 
definition

The problem is that
  - config.h is included more than once,
  - upon 1st inclusion, __has_attribute is not defined, because the compiler
    is gcc < 5,
  - then <sys/cdefs.h> gets included, which defines __has_attribute:

    #ifndef     __has_attribute
    #define     __has_attribute(x)      0
    #endif

  - then config.h is included again, and now this definition of
    _GL_HAS_ATTRIBUTE is used:

    #if (defined __has_attribute \
         && (!defined __clang_minor__ \
             || (defined __apple_build_version__ \
                 ? 6000000 <= __apple_build_version__ \
                 : 5 <= __clang_major__)))
    # define _GL_HAS_ATTRIBUTE(attr) __has_attribute (__##attr##__)
    #else

Thus a wrong definition of _GL_HAS_ATTRIBUTE prevails, that turns off all
attributes.

This patch fixes it.


2024-02-09  Bruno Haible  <bruno@clisp.org>

        Avoid suboptimal definition of _GL_HAS_ATTRIBUTE on FreeBSD/sparc64.
        * m4/gnulib-common.m4 (gl_COMMON_BODY): Define _GL_HAS_ATTRIBUTE only
        once.

diff -w --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4
index 00691c0d6c..d8d0904f78 100644
--- a/m4/gnulib-common.m4
+++ b/m4/gnulib-common.m4
@@ -1,4 +1,4 @@
-# gnulib-common.m4 serial 91
+# gnulib-common.m4 serial 92
 dnl Copyright (C) 2007-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -76,6 +76,11 @@ AC_DEFUN([gl_COMMON_BODY]
 #endif])
   AH_VERBATIM([attribute],
 [/* Attributes.  */
+/* Define _GL_HAS_ATTRIBUTE only once, because on FreeBSD, with gcc < 5, if
+   <config.h> gets included once again after <sys/cdefs.h>, __has_attribute(x)
+   expands to 0 always, and redefining _GL_HAS_ATTRIBUTE would turn off all
+   attributes.  */
+#ifndef _GL_HAS_ATTRIBUTE
 # if (defined __has_attribute \
       && (!defined __clang_minor__ \
           || (defined __apple_build_version__ \
@@ -113,6 +118,7 @@ AC_DEFUN([gl_COMMON_BODY]
 #  define _GL_ATTR_unused _GL_GNUC_PREREQ (2, 7)
 #  define _GL_ATTR_warn_unused_result _GL_GNUC_PREREQ (3, 4)
 # endif
+#endif
 
 /* Use __has_c_attribute if available.  However, do not use with
    pre-C23 GCC, which can issue false positives if -Wpedantic.  */






reply via email to

[Prev in Thread] Current Thread [Next in Thread]