Bug 80140 - missing -Wignored-attributes on function arguments; can lead to spurious -Wunused-parameter or -Wreturn-type
Summary: missing -Wignored-attributes on function arguments; can lead to spurious -Wun...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2017-03-21 20:42 UTC by Martin Sebor
Modified: 2021-03-26 23:25 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-08-23 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Sebor 2017-03-21 20:42:18 UTC
GCC ignores all five of the attributes in the test case below but only diagnoses one of them, on the declaration of f_ref_noreturn.  It should diagnose all of them.

$ cat t.C && gcc -S -Wall -Wextra -Wpedantic -Wignored-attributes t.C
void f_ptr_unused (void * __attribute__((unused)));

void f_ptr_unused (void *p)   // -Wunused issued regardless of attribute
{
}

int f_ptr_noreturn (void (*)() __attribute__((noreturn)));

int f_ptr_noreturn (void (*fp)())
{
  fp ();   // -Wreturn-type regardless of attribute
}


int f_ref_noreturn (void (&)() __attribute__((noreturn)));   // warning (ok)

int f_ptr_noreturn (void (&fr)())
{
  fr ();   // -Wreturn-type (expected, warning on declaration)
}


template <void (*FP)() __attribute__((noreturn))>
int ftempl_ptr_noreturn ()
{
  FP ();   // -Wreturn-type regardless of attribute
}

void f ();

template int ftempl_ptr_noreturn<&f>();

template <void (&FR)() __attribute__((noreturn))>
int ftempl_ref_noreturn ()
{
  FR ();   // -Wreturn-type regardless of attribute
}

template int ftempl_ref_noreturn<f>();

t.C: In function ‘void f_ptr_unused(void*)’:
t.C:3:26: warning: unused parameter ‘p’ [-Wunused-parameter]
 void f_ptr_unused (void *p)   // -Wunused issued regardless of attribute
                          ^
t.C: In function ‘int f_ptr_noreturn(void (*)())’:
t.C:12:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
t.C: At global scope:
t.C:15:56: warning: ‘noreturn’ attribute ignored [-Wattributes]
 int f_ref_noreturn (void (&)() __attribute__((noreturn)));   // warning (ok)
                                                        ^
t.C: In function ‘int f_ptr_noreturn(void (&)())’:
t.C:20:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
t.C: In function ‘int ftempl_ptr_noreturn()’:
t.C:27:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
t.C: In function ‘int ftempl_ref_noreturn()’:
t.C:37:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
Comment 1 Eric Gallager 2017-08-23 00:44:53 UTC
Confirmed. Also the location info for the one where it does print a -Wattributes warning could be improved, too, to underline the whole attribute rather than just a closing parenthesis.
Comment 2 Eric Gallager 2018-05-23 11:09:00 UTC
adding other warnings this bug provokes to the title
Comment 3 Eric Gallager 2018-11-23 03:31:31 UTC
(In reply to Eric Gallager from comment #1)
> Confirmed. Also the location info for the one where it does print a
> -Wattributes warning could be improved, too, to underline the whole
> attribute rather than just a closing parenthesis.

I think David Malcolm was doing something with the diagnostics systems that might be related to that part recently? cc-ing him