From ec33596f7be50689634067a22fdcc04e3bf48ae3 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 10 Feb 2023 03:53:24 +0100 Subject: [PATCH] Avoid clang warnings regarding [[__maybe_unused__]]. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * m4/gnulib-common.m4 (gl_COMMON_BODY): For clang versions ≥ 6, < 10, in C++ mode, ignore the __has_c_attribute value and define _GL_ATTRIBUTE_MAYBE_UNUSED to __attribute__ ((__unused__)), not [[__maybe_unused__]]. --- ChangeLog | 8 ++++++++ m4/gnulib-common.m4 | 14 ++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8e21cace23..9689c438b8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2023-01-28 Bruno Haible + + Avoid clang warnings regarding [[__maybe_unused__]]. + * m4/gnulib-common.m4 (gl_COMMON_BODY): For clang versions ≥ 6, < 10, + in C++ mode, ignore the __has_c_attribute value and define + _GL_ATTRIBUTE_MAYBE_UNUSED to __attribute__ ((__unused__)), not + [[__maybe_unused__]]. + 2023-01-25 Bruno Haible Keep config.h idempotent. diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4 index 2480f567a6..c820d29487 100644 --- a/m4/gnulib-common.m4 +++ b/m4/gnulib-common.m4 @@ -1,5 +1,5 @@ -# gnulib-common.m4 serial 73.2 -dnl Copyright (C) 2007-2022 Free Software Foundation, Inc. +# gnulib-common.m4 serial 73.3 +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, dnl with or without modifications, as long as this notice is preserved. @@ -347,9 +347,15 @@ AC_DEFUN([gl_COMMON_BODY], [ in C++ also: class. */ /* In C++ and C2x, this is spelled [[__maybe_unused__]]. GCC's syntax is __attribute__ ((__unused__)). - clang supports both syntaxes. */ + clang supports both syntaxes. Except that with clang ≥ 6, < 10, in C++ mode, + __has_c_attribute (__maybe_unused__) yields true but the use of + [[__maybe_unused__]] nevertheless produces a warning. */ #ifndef _GL_ATTRIBUTE_MAYBE_UNUSED -# if _GL_HAS_C_ATTRIBUTE (maybe_unused) +# if defined __clang__ && defined __cplusplus +# if __clang_major__ >= 10 +# define _GL_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]] +# endif +# elif _GL_HAS_C_ATTRIBUTE (maybe_unused) # define _GL_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]] # else # define _GL_ATTRIBUTE_MAYBE_UNUSED _GL_ATTRIBUTE_UNUSED -- 2.39.5