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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
      Known to work|                            |5.4.0
           Keywords|                            |diagnostic
   Last reconfirmed|                            |2016-06-13
                 CC|                            |msebor at gcc dot gnu.org
     Ever confirmed|0                           |1
            Summary|"ignoring attributes on     |[6/7 regression] unexpected
                   |template argument" in -O1   |warning: ignoring function
                   |and above                   |return attributes on
                   |                            |template argument
      Known to fail|                            |6.1.0, 7.0

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
I looked into this a bit and I'm not sure the warning works quite as intended
in this case.

First, the warning doesn't say which of the attributes is ignored, and so when
multiple attributes are specified, it suggests that all of them are ignored. 
But tests with single attributes show that only some trigger the warning,
raising the question of whether the warning works correctly.

Second, it's unclear to me what purpose the warning is meant to serve in this
case.  Since a function attribute always applies to the instance of the
function it decorates and never affects its type the warning doesn't indicate
anything unusual or unexpected, and only serves to confuse users.  (In cases
where the function is declared in a system header it's also unclear how the
should be avoided.)

Looking at the history of the warning for the test case, it started with
r222530 committed to fix bug 50800 which has to do with type attributes, not
those of functions (or variables), and there is no test that verifies that it
should be issued for the case of functions (or variables).  I'm inclined to
agree that this is a bug.  Confirming as a 6/7 regression with the test case
below:

$ cat t.C && /home/msebor/build/gcc-6-branch/gcc/xgcc -B
/home/msebor/build/gcc-6-branch/gcc -S -Wall -Wextra -Wpedantic t.C
void* __attribute__ ((assume_aligned (32))) f0 ();
void* __attribute__ ((returns_nonnull)) f1 ();

void* __attribute__ ((const)) f2 ();
void* __attribute__ ((const, warn_unused_result)) f3 ();

template <class T> struct S { };

S<decltype (&f0)> s0;
S<decltype (&f1)> s1;
S<decltype (&f2)> s2;   // no warning
S<decltype (&f3)> s3;   // which of the two attributes are ignored?
t.C:9:17: warning: ignoring attributes on template argument ‘void* (*)()’
[-Wignored-attributes]
 S<decltype (&f0)> s0;
                 ^
t.C:10:17: warning: ignoring attributes on template argument ‘void* (*)()’
[-Wignored-attributes]
 S<decltype (&f1)> s1;
                 ^
t.C:12:17: warning: ignoring attributes on template argument ‘void* (*)()’
[-Wignored-attributes]
 S<decltype (&f3)> s3;   // which of the two attributes are ignored?
                 ^

Reply via email to