bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: "Marc Nieper-Wißkirchen" <marc.nieper+gnu@gmail.com>
Cc: bug-gnulib@gnu.org
Subject: Re: Unused parameter warnings
Date: Sat, 10 Oct 2020 11:50:48 -0700	[thread overview]
Message-ID: <cacc5786-42e2-879e-6c58-1378a44d5a9b@cs.ucla.edu> (raw)
In-Reply-To: <CAEYrNrQeWx=cbPRQkUC0LeiL08pAvr2jVRRvi4eb+mM32xLXKg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 731 bytes --]

On 10/10/20 8:00 AM, Marc Nieper-Wißkirchen wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97364

Looking at that bug report and related material (particularly Richard Biener's 
2012 comment <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51971#c1>) the GCC 
folks seem to have decided long ago that const and pure attributes were intended 
more as directives for common subexpression elimination than as independent 
notions in their own right, it's just that they haven't gotten around to (or are 
embarrassed to :-) document that decision. In the meantime, to try to help out 
Gnulib hackers I installed the attached commentary changes. It was cleaner to 
document 'const' first so I rearranged the #defines.

[-- Attachment #2: 0001-attribute-improve-const-pure-doc.patch --]
[-- Type: text/x-patch, Size: 2923 bytes --]

From e3665e43f2a042b26fa65cdba80dd89846d95540 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sat, 10 Oct 2020 11:48:16 -0700
Subject: [PATCH] attribute: improve const, pure doc
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Problem reported by Marc Nieper-Wißkirchen in:
https://lists.gnu.org/r/bug-gnulib/2020-10/msg00035.html
* lib/attribute.h (ATTRIBUTE_CONST, ATTRIBUTE_PURE): Improv doc.  See:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51971#c1
---
 ChangeLog       |  8 ++++++++
 lib/attribute.h | 21 ++++++++++++---------
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 875f3551a..b479cf0c7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2020-10-10  Paul Eggert  <eggert@cs.ucla.edu>
+
+	attribute: improve const, pure doc
+	Problem reported by Marc Nieper-Wißkirchen in:
+	https://lists.gnu.org/r/bug-gnulib/2020-10/msg00035.html
+	* lib/attribute.h (ATTRIBUTE_CONST, ATTRIBUTE_PURE): Improv doc.  See:
+	https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51971#c1
+
 2020-10-05  Paul Eggert  <eggert@cs.ucla.edu>
 
 	thread: pacify GCC on Solaris 10
diff --git a/lib/attribute.h b/lib/attribute.h
index b97514655..48d9826c8 100644
--- a/lib/attribute.h
+++ b/lib/attribute.h
@@ -170,18 +170,21 @@
 /* Applies to: function.  */
 #define ATTRIBUTE_ALWAYS_INLINE _GL_ATTRIBUTE_ALWAYS_INLINE
 
-/* The function does not affect observable state, and always returns a value.
-   Compilers can omit duplicate calls with the same arguments if
-   observable state is not changed between calls.  (This attribute is
-   looser than ATTRIBUTE_CONST.)  */
+/* It is OK for a compiler to omit duplicate calls with the same arguments.
+   This attribute is safe for a function that neither depends on
+   nor affects observable state, and always returns exactly once -
+   e.g., does not loop forever, and does not call longjmp.
+   (This attribute is stricter than ATTRIBUTE_PURE.)  */
 /* Applies to: functions.  */
-#define ATTRIBUTE_PURE _GL_ATTRIBUTE_PURE
+#define ATTRIBUTE_CONST _GL_ATTRIBUTE_CONST
 
-/* The function neither depends on nor affects observable state,
-   and always returns a value.  Compilers can omit duplicate calls with
-   the same arguments.  (This attribute is stricter than ATTRIBUTE_PURE.)  */
+/* It is OK for a compiler to omit duplicate calls with the same
+   arguments if observable state is not changed between calls.
+   This attribute is safe for a function that does not affect
+   observable state, and always returns exactly once.
+   (This attribute is looser than ATTRIBUTE_CONST.)  */
 /* Applies to: functions.  */
-#define ATTRIBUTE_CONST _GL_ATTRIBUTE_CONST
+#define ATTRIBUTE_PURE _GL_ATTRIBUTE_PURE
 
 /* The function is rarely executed.  */
 /* Applies to: functions.  */
-- 
2.25.1


  reply	other threads:[~2020-10-10 18:51 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-04 20:23 Unused parameter warnings Marc Nieper-Wißkirchen
2020-10-04 22:08 ` Bruno Haible
2020-10-06  5:58   ` Marc Nieper-Wißkirchen
2020-10-06 21:05     ` Bruno Haible
2020-10-07  6:07       ` Marc Nieper-Wißkirchen
2020-10-10 13:50         ` Bruno Haible
2020-10-10 14:31           ` Marc Nieper-Wißkirchen
2020-10-10 14:39             ` Bruno Haible
2020-10-10 15:00               ` Marc Nieper-Wißkirchen
2020-10-10 18:50                 ` Paul Eggert [this message]
2020-10-10 21:00                   ` Bruno Haible
2020-10-11 23:10                     ` Paul Eggert
2020-10-12  2:21                       ` Jeffrey Walton
2020-10-14  1:24                     ` 'const' function attribute Bruno Haible
2020-10-14 14:57                       ` Paul Eggert
2020-10-18 14:27                         ` Bruno Haible
2020-10-10 20:43             ` Unused parameter warnings Bruno Haible

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cacc5786-42e2-879e-6c58-1378a44d5a9b@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=bug-gnulib@gnu.org \
    --cc=marc.nieper+gnu@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).