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.

Reply via email to