public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/100670] New: unused attribute ignored on function definition
@ 2021-05-19  8:43 vries at gcc dot gnu.org
  2021-05-19  9:34 ` [Bug c/100670] " vries at gcc dot gnu.org
  2021-05-19  9:46 ` rguenth at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: vries at gcc dot gnu.org @ 2021-05-19  8:43 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100670
           Summary: unused attribute ignored on function definition
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

Consider the following test-case:
...
$ cat foo.c
typedef void *void_ptr;

static TYPE __attribute__((unused))
foo (void)
{
  return 0;
}
...

Let's try with type int:
...
$ gcc-11 -c -Wall -O0 -g -Werror foo.c -DTYPE="int"
$
...
No warning.

Ok, now with void *:
...
$ gcc-11 -c -Wall -O0 -g -Werror foo.c -DTYPE="void *"
foo.c:4:1: error: ‘foo’ defined but not used [-Werror=unused-function]
    4 | foo (void)
      | ^~~
cc1: all warnings being treated as errors
...
Hmm, a warning.

Now with void_ptr:
...
$ gcc-11 -c -Wall -O0 -g -Werror foo.c -DTYPE="void_ptr"
$
...
again no warning.

My expectation was that there would be no warning for the "void *" case.

I cannot tell from the gcc attributes syntax documentation what is the correct
behaviour.

If this is not a compiler bug, then I suggest this is changed into a
documentation PR.

Note that there is at least one example that uses this style (
https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes
):
...
void __attribute__ ((visibility ("protected")))
f () { /* Do something. */; }
...

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

end of thread, other threads:[~2021-05-19  9:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-19  8:43 [Bug c/100670] New: unused attribute ignored on function definition vries at gcc dot gnu.org
2021-05-19  9:34 ` [Bug c/100670] " vries at gcc dot gnu.org
2021-05-19  9:46 ` rguenth 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).