public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/110029] New: more precise documentation for cleanup attribute
@ 2023-05-29 21:25 ian at airs dot com
  2023-05-29 21:37 ` [Bug c/110029] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: ian at airs dot com @ 2023-05-29 21:25 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110029
           Summary: more precise documentation for cleanup attribute
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ian at airs dot com
  Target Milestone: ---

The cleanup attribute is defined as running a function when a variable goes out
of scope.  However, the documentation does not clearly say what happens when
multiple variables are in scope.

For example:

#include <stdio.h>

static void adone (int *p __attribute__((unused))) {
  puts("adone");
}

static void bdone (int *p __attribute__((unused))) {
  puts("bdone");
}

void f () {
  int a __attribute__((cleanup (adone)));
  int b __attribute__((cleanup (bdone)));
  puts("f");
}

int main() {
  f ();
}

With the current implementation, this prints

f
bdone
adone

This follows from the implementation, which is that a cleanup attribute becomes
a try/finally construct at the point of the variable declaration.  But it does
not obviously follow from the documentation.

The documentation should be clear about this.  Thanks.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-01-20 17:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-29 21:25 [Bug c/110029] New: more precise documentation for cleanup attribute ian at airs dot com
2023-05-29 21:37 ` [Bug c/110029] " pinskia at gcc dot gnu.org
2024-01-19  2:10 ` cvs-commit at gcc dot gnu.org
2024-01-19  2:12 ` sandra at gcc dot gnu.org
2024-01-19 17:55 ` ian at airs dot com
2024-01-20 17:23 ` pinskia at gcc dot gnu.org

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).