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

            Bug ID: 127361
           Summary: [[gnu::copy]]ing from a function with [[unsequenced]]
                    type gives bogus -Wattributes warning
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rasheeqhere at gmail dot com
  Target Milestone: ---

Reproducer (no warning options needed, just plain "gcc -c test.c"; GCC 16.2 or
GCC trunk on x86_64 Linux):

    void foo(int*) [[unsequenced]];
    void bar [[gnu::copy(foo)]](int*);

GCC will print this warning:

    <source>:2:1: warning: standard 'unsequenced' attribute can only be applied
to function declarators or type specifiers with function type [-Wattributes]
        2 | void bar [[gnu::copy(foo)]](int*);
          | ^~~~
    <source>:2:1: note: did you mean to specify it after ')' following function
parameters?

I don't think this makes much sense. First of all, I'm not sure [[gnu::copy]]
should even try to copy the [[unsequenced]] attribute, since [[unsequenced]]
appertains to the function type but [[gnu::copy]] appertains to the
declarations. I would expect [[gnu::copy(foo)]] to copy only the attributes
appertaining to the declaration(s) of foo. In fact, my real use case actually
looked like

    typeof(foo) qux [[gnu::copy(foo)]];

This gives the same warning. In this example, I don't need/want [[gnu::copy]]
to copy [[unsequenced]] into qux's type, because the typeof should be handling
it already. The note about "specify it after ')' following function parameters"
also makes very little sense in the qux example, since there are neither
function parameters nor a "')' following function parameters" to speak of in
the declaration.

Extra weirdness: changing foo and bar to type int() stops the warnings. Adding
[[gnu::access(write_only, 1)]] to foo (between the identifier "foo" and the
"(") causes the warnings to apparently be doubled.

Here it is on Compiler Explorer: https://godbolt.org/z/Pv4Mj4KKh

Reply via email to