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

            Bug ID: 127932
           Summary: Wunused-but-set-parameter when using counted_by
                    attribute
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: b.buschinski at googlemail dot com
  Target Milestone: ---

For the code:

```
struct buffer {
    int * ptr __attribute__((counted_by(len)));
    unsigned int len;
};

int foo(struct buffer const buf)
{
    if (buf.ptr[0] != 0) {
        return 2;
    }

    return 1;
}

```

It gives a warning:

```
<source>:6:29: warning: parameter 'buf' set but not used
[-Wunused-but-set-parameter=]
    6 | int foo(struct buffer const buf)
      |         ~~~~~~~~~~~~~~~~~~~~^~~
```

but "buf" is actually used.

The warning disappears when "__attribute__((counted_by(len)))" is removed.

See compiler explorer: https://godbolt.org/z/csW3YnTEf

With GCC trunk and GCC-16.2

Reply via email to