From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 62BA11F47C for ; Sat, 28 Jan 2023 10:58:08 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=clisp.org header.i=@clisp.org header.a=rsa-sha256 header.s=strato-dkim-0002 header.b=LQYKzQ1T; dkim-atps=neutral Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLiu9-0004IK-Vp; Sat, 28 Jan 2023 05:57:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pLiu8-0004IA-Gt for bug-gnulib@gnu.org; Sat, 28 Jan 2023 05:57:52 -0500 Received: from mo4-p00-ob.smtp.rzone.de ([81.169.146.219]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pLiu6-0001DN-Do for bug-gnulib@gnu.org; Sat, 28 Jan 2023 05:57:52 -0500 ARC-Seal: i=1; a=rsa-sha256; t=1674903467; cv=none; d=strato.com; s=strato-dkim-0002; b=ZYaD3bSZby+XVvrfWkIMf+IN2L2P+PqzyjpDMMmJATF7vq73I6v63m711vj6UhvRp0 aj4tnT//oc8VEA8DmmQCYlE6GmgdISvKaLLLPJkO/Wz+kGLPk0fHDUrm8jthrkrTmhiG nhU8n0GZQGOM81pAdgVKNTmdvPaLmXw9dXFULqC+qDWeTtH8riVgRbcsh3mKiX9I24Bu 1HD56VB2KHoL4JFuIXKI6r9uhocftAX0merLSTy3wBvJCk+IvMjJxRbhLp+4py1Rg4NI 0YDISchJzcwYyqv2+lO64kFJJnvul1JDghV/dfx9drqrwbio6N0zuGCs94tGx5rF0Npw WXIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1674903467; s=strato-dkim-0002; d=strato.com; h=Message-ID:Date:Subject:To:From:Cc:Date:From:Subject:Sender; bh=lJIYQ1cuBak/rEhhtUu/OvoNNj5MRKyHN9YPDETq3G8=; b=RkDEIbBHID8igSUuKUh/yy7v7y4Dhsu/YINmGEdNUSb2wWE4+AuFUCtVNhPfc7R9dq /bAhJ22FhySXa5Y87ArVng8C3dtQTKoD3GcpUHqCDWWrmBhDJpZUF7djWzCU05R6L8YV PHKxUosNCoWWvsBlJ3UeG6qNQ+azo6pO9rblhtYAV/F8EuC9fUV/Rq3pQ70up5POvx8j qMmBTndPjJ7GkGmfENDtserXF6mLoyy3oLf4K9aYzZKx+QwZOPs4t6Gf0G16UTFxTvN9 UTaePaXRXIxApUMR01AFOdgNDldUMDbjJ6jaKrN2krG/G/3E9LxW04AbFfabJpuon9E3 xa7Q== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1674903467; s=strato-dkim-0002; d=clisp.org; h=Message-ID:Date:Subject:To:From:Cc:Date:From:Subject:Sender; bh=lJIYQ1cuBak/rEhhtUu/OvoNNj5MRKyHN9YPDETq3G8=; b=LQYKzQ1Ts0skCGF78ag+WjUyhIemGb7MURr6LCaumjYQQe7ub/Rafa6Fyq0AePr1CL a/ae4WfbfudyIsOYHGzpCHGlKtUmYQIowdIf2ViS7ehlVDYJNmo9OOPZNio60H0WRcGM S7kmE69hq0XbL9nni+ylUVelJmCdYTOphIGHcgX4mLGHD6Tmc3Mu6Oe7AMmjzvCtPRM7 xzXFiEax4XYZ+KHXCIvvsm20Ew1HzbgnYqbVo3w58zAP4Mc0xeQhywYa+km0zF3i6Kol SgiZQCEPA23mgb/k/qJjPsGwFJj1y5zVD4ZErfgxex/5Fyx7IAqEoX1oQ04aLCFyPF+i El2w== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH0WWb0LN8XZoH94zq68+3cfpPDjvwA7022TV+YfjovfFy3RIl4" Received: from nimes.localnet by smtp.strato.de (RZmta 49.2.2 AUTH) with ESMTPSA id 098542z0SAvkMuo (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Sat, 28 Jan 2023 11:57:46 +0100 (CET) From: Bruno Haible To: bug-gnulib@gnu.org Subject: Avoid clang warnings regarding [[__nodiscard__]] Date: Sat, 28 Jan 2023 11:57:46 +0100 Message-ID: <4082365.HAeao5ULc5@nimes> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Received-SPF: none client-ip=81.169.146.219; envelope-from=bruno@clisp.org; helo=mo4-p00-ob.smtp.rzone.de X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Building a Gnulib testdir on FreeBSD 12.0, which uses clang 6.0.1, I see several warnings such as ../../gltests/../gllib/gl_list.h:642:1: warning: unknown attribute '__nodiscard__' ignored [-Wunknown-attributes] The cause is that in this version of clang, __has_c_attribute(__nodiscard__) apparently returns true, but the use of [[__nodiscard__]] elicits a warning. Here's how it depends on the clang version: clang result ----- ------- 5.0.2 error 6.0.1 warning 7.0.1 warning 8.0.0 warning 9.0.0 warning 10.0.0 warning 11.0.0 warning 12.0.1 warning 13.0.0 warning 14.0.0 warning 15.0.6 warning This patch fixes the warnings, by choosing a different (more conservative) expansion of _GL_ATTRIBUTE_NODISCARD. 2023-01-28 Bruno Haible Avoid clang warnings regarding [[__nodiscard__]]. * m4/gnulib-common.m4 (gl_COMMON_BODY): For clang, in C++ mode, ignore the __has_c_attribute value and define _GL_ATTRIBUTE_NODISCARD to __attribute__ ((__warn_unused_result__)), not [[__nodiscard__]]. diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4 index cf0fc5a1e7..d632819864 100644 --- a/m4/gnulib-common.m4 +++ b/m4/gnulib-common.m4 @@ -1,4 +1,4 @@ -# gnulib-common.m4 serial 79 +# gnulib-common.m4 serial 80 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, @@ -379,7 +379,13 @@ AC_DEFUN([gl_COMMON_BODY], [ the return value, unless the caller uses something like ignore_value. */ /* Applies to: function, enumeration, class. */ #ifndef _GL_ATTRIBUTE_NODISCARD -# ifdef __has_c_attribute +# if defined __clang__ && defined __cplusplus + /* With clang up to 15.0.6 (at least), in C++ mode, [[__nodiscard__]] produces + a warning. */ +# if __clang_major__ >= 1000 +# define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]] +# endif +# elif defined __has_c_attribute # if __has_c_attribute (__nodiscard__) # define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]] # endif